无法绑定到“ngModel”,因为它不是“输入”的已知属性我在启动我的角度应用程序时有以下错误,即使组件没有显示。我要评论一下<input>这样我的应用程序就能工作了。 zone.js:461 Unhandled Promise rejection: Template parse errors:
Can't bind to 'ngModel' since it isn't a known property of 'input'. ("
<div>
<label>Created:</label>
<input type="text" [ERROR ->][(ngModel)]="test" placeholder="foo" />
</div>
</div>"): InterventionDetails@4:28 ; Zone: <root> ; Task: Promise.then ; Value:我在看英雄柱塞,但我没有看到与我的代码有任何区别。以下是组件文件: 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";
}
3 回答

九州编程
TA贡献1785条经验 获得超4个赞
import { FormsModule } from '@angular/forms';[...]@NgModule({ imports: [ [...] FormsModule ], [...]})

宝慕林4294392
TA贡献2021条经验 获得超8个赞

缥缈止盈
TA贡献2041条经验 获得超4个赞
[(ngModel)]
角/包/窗体/src/指令/ng_model.
FormsModule
import { BrowserModule } from '@angular/platform-browser';import { NgModule } from '@angular/core';import { FormsModule } from '@angular/forms'; //<<<< import it hereimport { AppComponent } from './app.component';@NgModule({ declarations: [ AppComponent ], imports: [ BrowserModule, FormsModule //<<<< and here ], providers: [], bootstrap: [AppComponent]})export class AppModule { }
ngModel
/** * `ngModel` forces an additional change detection run when its inputs change: * E.g.: * ``` * <div>{{myModel.valid}}</div> * <input [(ngModel)]="myValue" #myModel="ngModel"> * ``` * I.e. `ngModel` can export itself on the element and then be used in the template. * Normally, this would result in expressions before the `input` that use the exported directive * to have and old value as they have been * dirty checked before. As this is a very common case for `ngModel`, we added this second change * detection run. * * Notes: * - this is just one extra run no matter how many `ngModel` have been changed. * - this is a general problem when using `exportAs` for directives! */
ngModelOptions
[ngModelOptions]="{standalone: true}"
添加回答
举报
0/150
提交
取消