我是 Angular 的新手。我开始了《英雄之旅》来学习它。
所以,我被创建了一个app.component
with two-way
捆绑。
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'
};
}
按照教程,我导入了 FormsModule 并将其添加到声明数组中。这一步出现错误:
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 { }
这是错误:
未捕获错误:模块“AppModule”声明了意外的模块“FormsModule”。请添加@Pipe/@Directive/@Component注释。
FormsModule
应添加于imports array
not declarations array
.
-
导入数组用于导入模块,例如
BrowserModule
, FormsModule
, HttpModule
-
声明数组是为了你的
Components
, Pipes
, Directives
参考下面的变化:
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
FormsModule
],
providers: [],
bootstrap: [AppComponent]
})
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)