我的组件中有这个简单的输入,它使用 [(ngModel)]
:
<input type="text" [(ngModel)]="test" placeholder="foo" />
当我启动我的应用程序时,我收到以下错误,即使该组件没有显示。
zone.js:461 Unhandled Promise rejection: Template parse errors: Can't bind to 'ngModel' since it isn't a known property of 'input'.
这是component.ts:
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
],
[...]
})
关于javascript - 无法绑定(bind)到 'ngModel',因为它不是 'input' 的已知属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38892771/