我是Angular2世界(和JS/TS)的新手。到目前为止,我确实在网上找到了所有问题的答案(主要是在堆栈溢出上)。但我没有时间去工作。
我确实遵循了天使2-瞬间GitHub-页面上的说明,但是当我的应用程序加载时,我得到了以下错误:
angular2-polyfills.js:127 GET http://localhost:8080/angular2-moment 404 (Not Found)
http://localhost:8080/angular2-moment(…)Webstrom将导入作为:import {DateFormatPipe} from "angular2-moment/index";
我试图将其更改为:import {DateFormatPipe} from "angular2-moment";、import {DateFormatPipe} from "angular2-moment/DateFormatPipe";或import {DateFormatPipe} from "angular2-moment/DateFormatPipe.js";,但这并没有帮助。
如果将导入更改为import {DateFormatPipe} from "node_modules/angular2-moment/DateFormatPipe.js";,则会得到以下错误:
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
};
...顺便说一句:正确的导入(如import {DateFormatPipe} from "angular2-moment/index"; )确实有效。
发布于 2016-06-13 06:31:27
您需要配置模块加载器(我假设是SystemJS)来识别矩库。看看他们的柱塞例子,特别是config.js。您需要添加类似的内容:
System.config({
map: {
'moment': 'path/to/moment/library'
'angular2-moment': 'path/to/angular2-moment/library'
}
});也可以设置System.config.package,如果默认配置不起作用.
https://stackoverflow.com/questions/37777073
复制相似问题