【fcat-angular】angular-ngModel遇见的坑:Can't bind to 'ngModel' since it isn't a known property of 'input'

启动我的Angular应用程序时,出现以下错误,即使组件未显示。

我必须注释掉,以便我的应用程序工作。

zone.js:461 Unhandled Promise rejection: Template parse errors:
Can't bind to 'ngModel' since it isn't a known property of 'input'. ("
    
][(ngModel)]="test" placeholder="foo" />
"): InterventionDetails@4:28 ; Zone: ; Task: Promise.then ; Value:

我正在看Hero plucker,但是我没有看到任何区别。

这是组件文件:

import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { Intervention } from '../../model/intervention';

@Component({
    selector: 'intervention-details',
    templateUrl: 'app/intervention/details/intervention.details.html',
    styleUrls: ['app/intervention/details/intervention.details.css']
})

export class InterventionDetails
{
    @Input() intervention: Intervention;

    public test : string = "toto";
}

解决方法:

没错,就是在app.module.ts中,我刚刚添加了:

import { FormsModule } from '@angular/forms';

[...]

@NgModule({
  imports: [
    [...]
    FormsModule
  ],
  [...]
})

这样就解决了。


angular、spring cloud 开源实战项目源码:https://gitee.com/xfdm/FCat

QQ群:549141844

代码持续更新…

你可能感兴趣的:(【fcat-angular】angular-ngModel遇见的坑:Can't bind to 'ngModel' since it isn't a known property of 'input')