Bom Dia !
Eu quero fazer um combo, mas estou tendo muita dificuldade.
MEU FORM
form materialize class=“col s12” [formGroup]=“form” (ngSubmit)=“save()”
1 TENTATIVA:
select [formGroup]=“form” formControlName="name"
option *ngFor=“let user of users” value= {{user.name}}
{{user.name}}
/option
/select
2 TENTATIVA
select [(ngModel)]="user.name"
option *ngFor=“let user of users” value= {{user.id}}>{{user.name}}</option
/select
ERRO:
vendor.bundle.js:1710 ERROR Error: Uncaught (in promise): Error:
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>
Error:
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>