我已经编写了一个程序来打印“My First Angular 2 App”,但无法继续输出。 请建议我在哪里做错。
environment_app.component.ts
import { AnotherComponent } from './anotherComponent.component';
import {component,view} from "angular2/core";
@Component({
selector:'my-app'
template:'<h2>My First Angular 2 App</h2>'
})
export class AppComponent{
}
environment_main.ts
import {bootstrap} from "angular2/platform/browser/index"
import {AppComponent} from "./environment_app.component"
bootstrap(AppComponent);
的index.html
<html >
<head>
<title>Hello World</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/es6-shim/0.33.3/es6-shim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.20/system-polyfills.js"></script>
<script src="https://code.angularjs.org/2.0.0-beta.6/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.6/Rx.js"></script>
<script src="https://code.angularjs.org/2.0.0-beta.6/angular2.dev.js"></script>
<script src="node_modules/angular2/bundles/http.dev.js"></script>
<script>
System.config({
transpiler: 'typescript',
typescriptOptions: { emitDecoratorMetadata: true },
packages: {'app': {defaultExtension: 'ts'}},
map: { 'app': './angular2-demo/app' }
});
System.import('app/environment_main')
.then(null, console.error.bind(console));
</script>
</head>
<body>
<my-app>Loading...</my-app>
</body>
</html>
以下是我得到的错误:
angular2-polyfills.js:1243 Error: XHR error (404 Not Found) loading http://localhost:3000/angular2-demo/app/environment_main.ts
Error loading http://localhost:3000/angular2-demo/app/environment_main.ts
at o (system.src.js:4597)
at XMLHttpRequest.I.s.onreadystatechange [as _onreadystatechange] (system.src.js:4597)
at Zone.run (angular2-polyfills.js:1243)
at XMLHttpRequest.zoneBoundFn (angular2-polyfills.js:1220)
答案 0 :(得分:0)
这些是我为使其发挥作用而做出的一些改变:
environment_app.component.ts:
import {Component} from "angular2/core"; // capitalized 'Component'
@Component({
selector:'my-app'
template:'<h2>My First Angular 2 App</h2>'
})
export class AppComponent{
}
environment_main.ts:
import {bootstrap} from "angular2/platform/browser" // removed '/index'
import {AppComponent} from "./environment_app.component"
bootstrap(AppComponent);
的index.html:
<html >
<head>
<title>Hello World</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/es6-shim/0.33.3/es6-shim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.20/system-polyfills.js"></script>
<script src="https://code.angularjs.org/2.0.0-beta.6/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.6/Rx.js"></script>
<script src="https://code.angularjs.org/2.0.0-beta.6/angular2.dev.js"></script>
<script src="node_modules/angular2/bundles/http.dev.js"></script>
<script>
System.config({
transpiler: 'typescript',
typescriptOptions: { emitDecoratorMetadata: true },
packages: {'app': {
main: './environment_main.ts',
defaultExtension: 'ts'
}},
map: { 'app': './src' }
});
System.import('app')
.then(null, console.error.bind(console));
</script>
</head>
<body>
<my-app>Loading...</my-app>
</body>
</html>
以下是{{3}}