source

감지되지 않은 오류:'AppModule' 모듈에서 예기치 않은 모듈 'FormsModule'을(를) 선언했습니다.@Pipe/@Directive/@Component 주석을 추가하십시오.

nicesource 2023. 7. 28. 22:10
반응형

감지되지 않은 오류:'AppModule' 모듈에서 예기치 않은 모듈 'FormsModule'을(를) 선언했습니다.@Pipe/@Directive/@Component 주석을 추가하십시오.

앵귤러에 새로 왔어요.저는 그것을 배우기 위해 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 주석을 추가하십시오.

FormsModule다음 위치에 추가해야 합니다.imports array것은 아니다.declarations array.

  • 가져오기 어레이는 다음과 같은 모듈을 가져오기 위한 것입니다.BrowserModule,FormsModule,HttpModule
  • 선언 배열은 당신을 위한 것입니다.Components,Pipes,Directives

아래 변경 내용 참조:

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    FormsModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})

더하다FormsModule배열 가져오기에 있습니다.

@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
FormsModule
],
providers: [],
bootstrap: [AppComponent]
})

또는 사용하지 않고 수행할 수 있습니다.[(ngModel)]을 이용하여

<input [value]='hero.name' (input)='hero.name=$event.target.value' placeholder="name">

대신에

<input [(ngModel)]="hero.name" placeholder="Name">

선언에서 양식 모듈 제거: [] 및 가져오기에 양식 모듈 추가: []

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    FormsModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})

추가할 수 있는 항목declarations: [] in modules

  • 파이프
  • 지시문
  • 요소

전문가 팁:오류 메시지가 설명합니다.Please add a @Pipe/@Directive/@Component annotation.

언급URL : https://stackoverflow.com/questions/45032043/uncaught-error-unexpected-module-formsmodule-declared-by-the-module-appmodul

반응형