I have a FormGroup as follow :
public form = this.fb.group({
name: ['', [Validators.minLength(3), Validators.required]],
category: ['', [Validators.required]],
start_date: ['', [Validators.required]],
end_date: ['', [Validators.required]],
front_image: ['', [Validators.required]],
description: ['']
}, {validators: [verifyDates]})
And my select field in the html formGroup as follow :
<ion-item>
<ion-label>{{'selectCat' | translate}}</ion-label>
<ion-select placeholder="{{'selectCatPlaceholder' | translate}}" formControlName="category" required>
<ion-select-option *ngFor="let cat of catService.categories" [value]="cat">{{cat.get('name_' + trans.currentLang)}}</ion-select-option>
</ion-select>
</ion-item>
Is there a way to check the correct option from the controller ?
I'm updating the form control on init in this mannear
this.form.get('category').setValue(cat[0])
It updates the form value correctly but does not check the box on the frontend. I use form builder and not ngModels and I used to use ngModels with formControl before but not it says we can't anymore and I can't find a way to do it. Can someone help ?
Try this