Typescript 在Angular2中使用外部打字脚本库(例如Angular2矩)
我对Angular2世界(和JS/TS)是新手。到目前为止,我确实在网上找到了我所有问题的答案(主要是关于stackoverflow)。但我没能有时间工作 我确实按照上的说明进行了操作,但在我的应用程序加载时出现以下错误:Typescript 在Angular2中使用外部打字脚本库(例如Angular2矩),typescript,angular,momentjs,Typescript,Angular,Momentjs,我对Angular2世界(和JS/TS)是新手。到目前为止,我确实在网上找到了我所有问题的答案(主要是关于stackoverflow)。但我没能有时间工作 我确实按照上的说明进行了操作,但在我的应用程序加载时出现以下错误: angular2-polyfills.js:127 GET http://localhost:8080/angular2-moment 404 (Not Found) http://localhost:8080/angular2-moment(…) Webstrom以以下方
angular2-polyfills.js:127 GET http://localhost:8080/angular2-moment 404 (Not Found)
http://localhost:8080/angular2-moment(…)
Webstrom以以下方式进行导入:
从“angular2矩/索引”导入{DateFormatPipe}代码>
我尝试将此更改为:
从“angular2矩”导入{DateFormatPipe}代码>,从“angular2矩/DateFormatPipe”导入{DateFormatPipe}
或从“angular2矩/DateFormatPipe.js”导入{DateFormatPipe}代码>但这没有帮助
如果我将导入从“node_modules/angular2 moment/DateFormatPipe.js”更改为import{DateFormatPipe}代码>我得到以下错误:
GET http://localhost:8080/moment 404 (Not Found)
http://localhost:8080/moment(…)
我不知道我做错了什么,这里需要一些帮助。非常感谢你的帮助
我使用angular2 rc,并希望像这样使用它:
@Component({
selector: ...,
template: ...,
pipes: [DateFormatPipe]
})
编辑:多亏@Sasxa,我才能够解决我的问题。但我仍然需要弄清楚一点,所以我会发布我的精确解。我将我的system.config.js
更改为:
....
var map = {
'app': 'build/app', // 'dist',
'@angular': 'node_modules/@angular',
'angular2-in-memory-web-api': 'node_modules/angular2-in-memory-web-api',
'rxjs': 'node_modules/rxjs',
'moment': 'node_modules/moment/moment.js', //<--this
'angular2-moment': 'node_modules/angular2-moment' //<--this
};
// packages tells the System loader how to load when no filename and/or no extension
var packages = {
'app': { main: 'main.js', defaultExtension: 'js' },
'rxjs': { defaultExtension: 'js' },
'angular2-in-memory-web-api': { main: 'index.js', defaultExtension: 'js' },
'angular2-moment': { defaultExtension: 'js' }//<--this
};
...
。。。。
变量映射={
'应用程序':'构建/应用程序',//'距离',
“@angular”:“node_modules/@angular”,
'angular2内存web api':'node_模块/angular2内存web api',
'rxjs':'node_modules/rxjs',
“矩”:“node_modules/moment/moment.js”,//您需要配置模块加载器(我假设它是SystemJS)来识别矩库。具体来看,config.js
。您需要添加类似的内容:
System.config({
map: {
'moment': 'path/to/moment/library'
'angular2-moment': 'path/to/angular2-moment/library'
}
});
如果默认配置不起作用,也可以设置System.config.package