how to use underscore.js library in angular 2

前端 未结 6 1217
夕颜
夕颜 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:02

    For a project based on https://cli.angular.io, I needed to do the following:

    1) Import libraries

    npm install underscore --save
    npm install @types/underscore --save
    

    2) in tsconfig.app.json, add underscore to array 'types':

    "types": [
      "underscore"
    ]
    

    3) In any component file I need to use underscore, I add this

    import * as _ from 'underscore';
    

    4) then I can use:

    console.log('now: ', _.now());
    

    and all functions of http://underscorejs.org

提交回复
热议问题