温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

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

发布时间:2020-07-16 03:07:20 来源:网络 阅读:4125 作者:vjjy001 栏目:开发技术

为了更好地在angular2 里面对JSON 数据进行处理。我们可以添加lodash模块来更加简便我们的工作

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

前提:

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

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

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

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



1 通过npm 安装lodash.这里可以通过以下命令行来安装

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

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


2 在system.config.js 文件添加如下

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

}


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

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);
			});
        }
	


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI