升級到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