我在使用 [(ngModel)]
的组件中有这个简单的输入:
<input type="text" [(ngModel)]="test" placeholder="foo" />
当我启动我的应用程序时,我收到以下错误,即使该组件未显示。
zone.js:461 未处理的承诺拒绝:模板解析错误:
无法绑定到“ngModel”,因为它不是“输入”的已知属性。
这是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";
}
原文由 Anthony Brenelière 发布,翻译遵循 CC BY-SA 4.0 许可协议
对,就是那样。在 app.module.ts 文件中,我刚刚添加了: