【发布时间】:2016-08-14 11:35:52
【问题描述】:
在我的 Angular 2 应用程序中,我在导入 Angular 或我的应用程序组件以外的依赖项时遇到问题。 (例如 angular2-moment)
我有<base href="/">
应用程序通过 main 运行(compilation.js 包含所有应用程序模块):
<script src="/app/compilation.js"></script>
<script>
System.config({
packages: {
app: {
format: 'register',
defaultExtension: 'js'
}
}
});
System.import('main')
.then(null, console.error.bind(console));
</script>
只要我从 node_modules 注入除 Angular 之外的任何内容,它就会导致编译失败。我从 main 得到一个 404。
import {Component} from "angular2/core";
import {ROUTER_PROVIDERS} from 'angular2/router';
import {HTTP_PROVIDERS} from "angular2/http";
import "rxjs/Rx";
import {HeaderComponent} from "./header/header.component";
import {HomeComponent} from "./home/home.component";
import {SidebarComponent} from "./side-bar/sidebar.component";
import {RouteConfig, ROUTER_DIRECTIVES} from "angular2/router";
import {enableProdMode} from "angular2/core";
//import {TimeAgoPipe} from 'angular2-moment'; <-- this breaks main (404)
控制台错误:
GET http://localhost:3001/main 404 (Not Found)
scheduleTask @ angular2-polyfills.js:126
tsconfig 是:
{
"compilerOptions": {
"target": "es5",
"module": "system",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false,
"outDir": "app/",
"outFile": "app/compilation.js",
"declaration": true
},
"exclude": [
"node_modules",
"typings/main",
"typings/main.d.ts"
]
}
非常感谢任何帮助我节省更多头发的帮助。
【问题讨论】:
-
我假设您的意思是“导入”而不是“注入”。注入是配置提供者并将构造函数参数添加到服务和组件以由 Angulars DI 传递。
标签: typescript angular base-url es6-module-loader