Tôi là người mới trong Angular. Tôi bắt đầu Tour of Heroes để tìm hiểu nó. Vì vậy, tôi được tạo ra app.component
với two-way
ràng buộc.
import { Component } from '@angular/core';
export class Hero {
id: number;
name: string;
}
@Component({
selector: 'app-root',
template: `
<h1>{{title}}</h1>
<h2>{{hero.name}} details!</h2>
<div><label>id: </label>{{hero.id}}</div>
<div><label>Name: </label>
<input [(ngModel)]="hero.name" placeholder="Name">
</div>
`,
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'Tour of Heroes';
hero: Hero = {
id: 1,
name: 'Windstorm'
};
}
Theo hướng dẫn, tôi đã nhập FormsModule và thêm nó vào mảng khai báo. Lỗi xuất hiện ở bước này:
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { FormsModule } from '@angular/forms';
@NgModule({
declarations: [
AppComponent,
FormsModule
],
imports: [
BrowserModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
Đây là lỗi:
Lỗi chưa xảy ra: Mô-đun không mong muốn 'FormsModule' được khai báo bởi mô-đun 'AppModule'. Vui lòng thêm chú thích @ Pipe / @ Chỉ thị / @ Thành phần.
imports
và khôngdeclarations