how to use underscore.js library in angular 2

前端 未结 6 1238
夕颜
夕颜 2020-12-29 20:47

I trying to create an application with angular 2,and want use underscore.js library in my .ts files ,for example when i want use this function :

   let myId         


        
6条回答
  •  半阙折子戏
    2020-12-29 21:19

    Check this repo. It has an example for underscore

    https://github.com/angular/angular-cli/wiki/3rd-party-libs#adding-underscore-library-to-your-project

    I did this on my imports to make it work

    //Place this at the top near your imports
    /// 
    import {Injectable} from '@angular/core';
    import {Http} from '@angular/http';
    import * as _ from 'underscore';
    

    Make sure you have the right reference path to underscore typings.

提交回复
热议问题