我正在尝试在非npm模式下使用angular2(运行tomcat服务器)。服务器端使用java-spring从索引页面开始加载依赖脚本。
在我的index.html上,导入为,
<script src="https://code.angularjs.org/2.0.0-beta.9/angular2-polyfills.js"></script>
<script src="https://code.angularjs.org/tools/system.js"></script>
<script src="https://code.angularjs.org/tools/typescript.js"></script>
<script src="https://code.angularjs.org/2.0.0-beta.9/Rx.js"></script>
<script src="https://code.angularjs.org/2.0.0-beta.9/angular2.dev.js"></script>
<script src="https://code.angularjs.org/2.0.0-beta.9/http.dev.js"></script>
<script src="https://code.angularjs.org/2.0.0-beta.9/router.dev.js"></script>
<script src="https://code.angularjs.org/2.0.0-beta.9/testing.dev.js"></script>
在System.js上将打字稿配置为
<script>
System.config({
transpiler: 'typescript',
typescriptOptions: { emitDecoratorMetadata: true },
packages: {'app': {defaultExtension: 'ts'}}
});
System.import('app/main.browser')
.then(null, console.error.bind(console));
</script>
其余的模块引用除了表单外,还可以将模块导入为
import { NgModule } from "angular2/core";
import { CommonModule } from "angular2/common";
import {
FormsModule,
ReactiveFormsModule
} from "angular2/forms";
在加载时间索引文件时,我得到以下异常:
angular2-polyfills.js:1243 Error: XHR error (404) loading http://localhost:8080/angular2/forms
Error loading http://localhost:8080/angular2/forms as "angular2/forms" from http://localhost:8080/app/schema-form/schema-form.module.ts
at o (https://code.angularjs.org/tools/system.js:4:12694)
at XMLHttpRequest.I.s.onreadystatechange [as _onreadystatechange] (https://code.angularjs.org/tools/system.js:4:13219)
at Zone.run (https://code.angularjs.org/2.0.0-beta.9/angular2-polyfills.js:1243:24)
at XMLHttpRequest.zoneBoundFn (https://code.angularjs.org/2.0.0-beta.9/angular2-polyfills.js:1220:26)
对此表示赞赏。
答案 0 :(得分:0)
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
我认为你应该从@angular/core
而不是angular2/core
导入。现在它的@ angular / core会改变它。