如何在angular 2中使用underscore.js库 [英] how to use underscore.js library in angular 2

查看:137
本文介绍了如何在angular 2中使用underscore.js库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创建一个角度为2的应用程序,并想在我的.ts文件中使用underscore.js库,例如,当我想要使用此功能时:

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 = _.rest([5, 4, 3, 2, 1]);

_未定义并引发错误,我不想在模块中使用declare var _ : any;

_ is not define and throw error and i dont want use declare var _ : any; in my module

推荐答案

您必须为下划线添加TypeScript定义:

You have to Add TypeScript Definitions for Underscore:

tsd安装下划线

tsd install underscore

配置SystemJS

Configure SystemJS

System.config({
  [...]
  paths: {
    underscore: './node_modules/underscore/underscore.js'
  }
});

最后导入模块

import * as _ from 'underscore';

这篇关于如何在angular 2中使用underscore.js库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆