Hi guys,
I have an object that has to be edited using a formcontrol. It works well with input fields, but I cannot figure out how to update an ionic-select field with the previous value if it’s an object.
I have to point out that the category field is an object also with the following format:
let catItem = {
id: cat.id,
name: cat.name
};
…
The form is filled as following:
console.log("Item category: "+this.category);
let catChoice = this.cats.find(cat => cat.id === this.category );
this.myForm.patchValue({
title: this.title,
category: catChoice,
due: this.due,
dueHour: this.due +' '+this.dueHour,
desc: this.desc,
});
//this.myForm.controls['category'].setValue(catChoice);
console.log("Form category: "+JSON.stringify(this.myForm.value['category']) );
I have also printed on console the value and is correct, but when I view the form the ionic-select is empty.
I have also tried to set individually the value with a setValue with no success (commented on the code), I tried also to put the cat.id or the cat.name, obviously with no success neither.
The select is filled as following:
<ion-select placeholder="Select Category" formControlName="category" required>
<ion-select-option *ngFor="let cat of cats" value="{{cat.id}}">{{cat.name}}</ion-select-option>
</ion-select>
Any idea why?