在Angular2 如何经过npm安装lodash模块

为了更好地在angular2 里面对JSON 数据进行处理。咱们能够添加lodash模块来更加简便咱们的工做node

这里我简单介绍一下如何安装lodash 到angular2typescript

前提:npm

01 这里默认已经安装了node.js。数组

02 默认typescript 版本>2.0 eg "typescript": "^2.0.3",bash

03 默认已经建立angular2 npm 架构的项目angular2

wKioL1gqOJqg2lM_AABTjpJrg-M050.png-wh_50



1 经过npm 安装lodash.这里能够经过如下命令行来安装架构

$ npm i -g npm
$ npm i --save lodash
$ npm install --save @types/lodash //this is for typescript

安装完成后node_modules 文件夹多出一个lodash文件夹ide


2 在system.config.js 文件添加以下测试

map:{
...
,
'lodash': 'node_modules/lodash/lodash.js',

}


3 建立一个测试component 或者service 来引用这个lodash模块this

import * as _ from 'lodash';



4测试lodash是否可使用。我在ngOnInit()下调用lodash, 能够是否能够遍历数组

ngOnInit(){
            console.log('lodash version:', _.VERSION);
			this.logger.logger("test logger");
			var test = _.each([1,2,3,4],function(v){
				console.log(v);
			});
        }
	
相关文章
相关标签/搜索