Angular2 - Angular-CLI installing lodash - Cannot find module

前端 未结 5 1850
庸人自扰
庸人自扰 2020-12-19 02:19

Mac OSX El capitan | angular-cli: 0.1.0 | node: 5.4.0 | os: darwin x64

I try to install a 3rd party npm module according to the angular-cli wiki: https://github.com/

5条回答
  •  抹茶落季
    2020-12-19 02:43

    [updated answer] After the new version of angular-cli (1.0.0-beta.15):

    just add

    npm install lodash --save
    npm install @types/lodash --save-dev
    

    then add the library to the angular-cli.json to list of global scripts(add "../node_modules/lodash/lodash.js" to the list apps[0].scripts).

    and in your component where you want to use , try this way

    declare var _:any;
    
    @Component({
    })
    export class YourComponent {
      ngOnInit() {
         console.log(_.chunk(['a', 'b', 'c', 'd'], 2));
      }
    }
    

    before : angular-cli (1.0.0-beta.15):

    add this line in src/index.html

      
    

    and in your component where you want to use , try this way

    declare var _:any;
    
    @Component({
    })
    export class YourComponent {
      ngOnInit() {
         console.log(_.chunk(['a', 'b', 'c', 'd'], 2));
      }
    }
    

    I tried straight away , it worked for me

提交回复
热议问题