how to use underscore.js library in angular 2

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

    For a project based on the angular2-seed, I needed to:

    1. Install underscore package:

      npm install underscore --save
      
    2. Add following to typings.json under globalDependencies:

      "underscore": "github:DefinitelyTyped/DefinitelyTyped/underscore",
      
    3. Add following under project.config.ts:

      this.SYSTEM_CONFIG_DEV.paths['underscore'] =
          `${this.APP_BASE}node_modules/underscore`;
      this.SYSTEM_BUILDER_CONFIG.packages['underscore'] = {
          main: 'underscore.js',
          defaultExtension: 'js'
      };
      
    4. Import "_" in my ts files:

      import * as _ from 'underscore';
      

提交回复
热议问题