2016-06-21 62 views
3

我想弄清楚如何在Angular CLI环境中使用各种第三方库。官方wiki page对于通过moment.js lib进行开发非常有用。虽然该错误信息显示为“在Angular CLI中使用第三方库类型

angular-cli: 1.0.0-beta.5 
node: 4.4.4 
os: darwin x64 
typings: 1.0.5 

typings install moment --save 

typings WARN hastypings Typings for "moment" already exist in 
"node_modules/moment/moment.d.ts". You should let TypeScript resolve 
the packaged typings and uninstall the copy installed by Typings 

typings ERR! message Unable to find "moment" ("npm") in the registry. 
Did you want to try searching another source? Also, if you want contribute 
these typings, please help us: https://github.com/typings/registry 

我的设置以供参考:但是,我尝试安装分型的库(在本教程的步骤1A)时遇到了麻烦卸载由Typings安装的副本“似乎没有新的.d.ts文件添加到项目文件夹中。在这种情况下,包含第三方类型的最佳方式是什么?

+0

你有没有解决您的问题,一个开源库?你正在使用哪个版本的angular2? –

回答

0

简答题:运行npm install @types/moment

说明:

这里至少有一些问题。 (1)作为TypeScript团队announced,“在TypeScript 2.0中获取类型声明将需要除npm之外没有工具”(强调他们的)。这意味着需要安装typingshas been deprecated和npm来安装打字文件。一个简单的例子是npm install --save @types/lodash。记下@types。所有类型现在在node_modules/@types。考虑到这一点,我们可以看看你的第二个问题。 (2)您正在使用typings,TypeScript 1工具,angular-cli,它使用TypeScript 2.它们不兼容。相反,您可以使用npm install @types/moment安装momentjs的类型。

最后 - 而不是直接关系到你的问题 - 你可能感兴趣的angular2-moment,该端口momentjs到角2