반응형
포착되지 않은 오류 : 'AppModule'모듈에서 예기치 않은 모듈 'FormsModule'을 선언했습니다. @ Pipe / @ Directive / @ Component 주석을 추가하십시오.
저는 Angular를 처음 사용합니다. 나는 그것을 배우기 위해 Tour of Heroes를 시작했습니다. 그래서, 나는 창조하고 app.component함께 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 주석을 추가하십시오.
FormsModuleimports arraynot에 추가해야합니다 declarations array.
- imports array 는
BrowserModule,, 같은 모듈을 가져 오기위한 것입니다FormsModule.HttpModule - 선언의 배열이 당신입니다
Components,Pipes,Directives
아래 변경 사항을 참조하십시오.
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
FormsModule
],
providers: [],
bootstrap: [AppComponent]
})
Add FormsModule in Imports Array.
i.e
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
FormsModule
],
providers: [],
bootstrap: [AppComponent]
})
Or this can be done without using [(ngModel)] by using
<input [value]='hero.name' (input)='hero.name=$event.target.value' placeholder="name">
instead of
<input [(ngModel)]="hero.name" placeholder="Name">
Remove the FormsModule from Declaration:[] and Add the FormsModule in imports:[]
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
FormsModule
],
providers: [],
bootstrap: [AppComponent]
})
반응형
'developer tip' 카테고리의 다른 글
| 멀티 파트 파일을 파일로 변환하는 방법? (0) | 2020.10.18 |
|---|---|
| java.io.IOException : Hadoop 바이너리에서 null \ bin \ winutils.exe 실행 파일을 찾을 수 없습니다. (0) | 2020.10.18 |
| 더 빠른 것은 무엇입니까, 문자열 또는 elseif on type? (0) | 2020.10.18 |
| 펄의 foreach 루프에서 자동으로 루프 인덱스를 얻습니다. (0) | 2020.10.18 |
| 두 장고 쿼리 셋의 합집합을 어떻게 찾을 수 있습니까? (0) | 2020.10.18 |