Tôi có những file sau và mã: index.html
:Góc thành phần chính 2 bootstrapping không làm việc
<!doctype html>
<html>
<head lang="en">
<title>Angular 2 Components</title>
</head>
<body>
<ngc-app></ngc-app>
<script src="https://cdnjs.cloudflare.com/ajax/libs/es6-shim/0.35.0/es6-shim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/2.0.0-beta.15/angular2-polyfills.js"></script>
<script src="jspm_packages/system.js"></script>
<script src="config.js"></script>
<script>
System.import('lib/bootstrap.js');
</script>
</body>
</html>
bootstrap.js
:
// Import Angular bootstrap function
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
// Import our main app component
import {App} from './app';
// We are bootstrapping Angular using our main application component
bootstrap(App);
app.js
:
// We need the Component annotation as well as the
// ViewEncapsulation enumeration
import {Component, ViewEncapsulation} from '@angular/core';
// Using the text loader we can import our template
import template from './app.html!text';
// This creates our main application component
@Component({
// Tells Angular to look for an element <ngc-app> to create this component
selector: 'ngc-app',
// Let's use the imported HTML template string
template,
// Tell Angular to ignore view encapsulation
encapsulation: ViewEncapsulation.None
})
export class App {}
và tôi tập app.html
:
<div>Hello World!</div>
Và package.json
:
{
"name": "taskmanagement",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"jspm": "^0.16.52"
},
"jspm": {
"dependencies": {
"@angular/common": "npm:@angular/[email protected]^2.4.7",
"@angular/compiler": "npm:@angular/[email protected]^2.4.7",
"@angular/core": "npm:@angular/[email protected]^2.4.7",
"@angular/platform-browser-dynamic": "npm:@angular/[email protected]^2.4.7",
"rxjs": "npm:[email protected]^5.1.0",
"text": "github:systemjs/[email protected]^0.0.9"
},
"devDependencies": {
"typescript": "npm:[email protected]^2.0.7"
}
}
}
Nhưng trong trình duyệt của nó cho thấy các lỗi sau:
Tôi đã tìm kiếm và phát hiện ra rằng mỗi thành phần chính là sống bên NgModule
, nhưng theo cuốn sách tôi đang đọc, không có bất kỳ mô-đun nào cho điều đó, và không phải là menti để tạo ra cái đó. Vì vậy, vấn đề với điều này là gì và tôi có nên tạo tệp mô-đun không? Để được trợ giúp và hướng dẫn cảm ơn.
câu trả lời bạn chọn không trả lời được câu hỏi của bạn. Nó thậm chí không có vẻ là tác giả đọc câu hỏi của bạn. Làm sao nó có thể giải quyết được vấn đề của bạn? –