2017-04-19 3 views
0

ng-model을 사용할 수 없습니다. 가져 오기 후에도이 오류가 발생합니다. forms.module in app.module.ts 아래는 파일 구성 요소와 모듈입니다. 내가 틀린 곳에서 나를 교정 해주세요. 덕분에 사전ng-model을 (를) 사용할 수 없습니다.

Promise rejection: Template parse errors: 
Can't bind to 'ng-model' since it isn't a known property of 'input'. (" 
      <div> 
        <label>name: </label> 
        <input type="text" [ERROR ->][(ng-model)]="hero.name" placeholder="name"> 
      </div> 
    "): ng:///AppModule/[email protected]:28 ; Zone: <root> ; Task: Promise.then ; Value: Error: Template parse errors:`enter code here` 
Can't bind to 'ng-model' since it isn't a known property of 'input'. (" 
      <div> 
        <label>name: </label> 
        <input type="text" [ERROR ->][(ng-model)]="hero.name" placeholder="name"> 
      </div> 
    "): ng:///AppModule/[email protected]:28 
    at syntaxError (http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:1513:34) [<root>] 
    at TemplateParser.parse (http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:11522:19) [<root>] 
    at JitCompiler._compileTemplate (http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:25296:39) [<root>] 
    at eval (http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:25220:62) [<root>] 
    at Set.forEach (native) [<root>] 
    at JitCompiler._compileComponents (http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:25220:19) [<root>] 
    at createResult (http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:25105:19) [<root>] 
    at Zone.run (http://localhost:3000/node_modules/zone.js/dist/zone.js:125:43) [<root> => <root>] 
    at http://localhost:3000/node_modules/zone.js/dist/zone.js:760:57 [<root>] 
    at Zone.runTask (http://localhost:3000/node_modules/zone.js/dist/zone.js:165:47) [<root> => <root>] 
    at drainMicroTaskQueue (http://localhost:3000/node_modules/zone.js/dist/zone.js:593:35) [<root>] 
    at XMLHttpRequest.ZoneTask.invoke (http://localhost:3000/node_modules/zone.js/dist/zone.js:464:25) [<root>] Error: Template parse errors: 

이 내 app.module.ts입니다 :

import { NgModule }  from '@angular/core'; 
import { BrowserModule } from '@angular/platform-browser'; 
import { FormsModule } from '@angular/forms'; 

import { AppComponent } from './app.component'; 

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

이 내 app.component.ts입니다 :

import { Component } from '@angular/core'; 
export class Hero{ 
    id: number; 
    name: string; 
} 
@Component({ 
    selector: 'my-app', 
    template: `<h1>{{title}}</h1> 
      <h2>{{hero.name}} details!</h2> 
      <div><label>id: </label>{{hero.id}}</div> 
      <div> 
        <label>name: </label> 
        <input type="text" [(ng-model)]="hero.name" placeholder="name"> 
      </div> 
    ` 
}) 
export class AppComponent { 
title = 'Angular'; 
    hero :Hero = { 
     id: 1, 
     name: 'windstorm' 
    }; 
    } 

답변

0

그것은 ngModel하지 ng-model입니다.

그래서 그것은해야한다 :

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

Template Syntax를 참조하십시오.

+0

감사합니다. – Tushar