升级到RC5后,我们开始收到此错误:ngModel不能使用与父formGroup指令注册表单控件
ngModel cannot be used to register form controls with a parent formGroup directive. Try using
formGroup's partner directive "formControlName" instead. Example:
<div [formGroup]="myGroup">
<input formControlName="firstName">
</div>
In your class:
this.myGroup = new FormGroup({
firstName: new FormControl()
});
Or, if you'd like to avoid registering this form control, indicate that it's standalone in ngModelOptions:
Example:
<div [formGroup]="myGroup">
<input formControlName="firstName">
<input [(ngModel)]="showMoreControls" [ngModelOptions]="{standalone: true}">
</div>
它看起来像在RC5两个不能再一起使用,但我可以没有找到替代解决方案。
这里是产生异常的组件:
<select class="field form-control" [formGroup]="form" [(ngModel)]="cause.id" [name]="name">
<option *ngFor="let c of causes" [value]="c.text">{{c.text}}</option>
</select>
您是否导入了'FormsModule'和'ReactiveFormsModule'? –
当然,他们两个 – user2363245
AFAIK,唯一现有的解释是以下内容:http://blog.angular-university.io/introduction-to-angular-2-forms-template-driven-vs-model-driven/ – user2363245