Hello Ionic people,
I have a select that is dynamically (and correctly) updated (value and options) on page load but not showed.
I need to manually trigger the select (just need to open the alert) to see it updated to the right value.
If i manually set the options array from the Constructor, the select is correctly set and i can read the default selected option without touching it.
But if start with a void Options list and later i update that with an array of objects, the options and the select value are correctly updated but not shown.
If i manually open the select, i see it changes behind the alert window, setting to the right option.
<ion-select multiple="{{config.multiple}}" [formControlName]="config.name" (ionChange)=" triggerChange($event) ">
<ion-select-option *ngFor="let option of config.options" [value]="option.id" [selected]="option.id == id_food">
{{ option.name }}
</ion-select-option>
</ion-select>
public triggerChange(event){
console.log(event,this.config)
}
(Works fine, always see the console log, event onChange correctly triggered on page load.)
This works-> static options, dynamic value. Value is set, on page load i see “Pizza”
this.formDefinition = [
{ name: 'id', type: 'inputSelect', label: 'Name', options: [ { id:1, name: 'Pizza', }, { id:2, name: 'Hot Dogs', }], multiple: false },
...
setFormvalues(values){
this.form.setFormValues(values);
}
This don’t work-> dynamic options, dynamic value. Options and value are set, but on page load i don’t see “Pizza” (but if i click the select without modifying anything, “Pizza” become selected)
this.formDefinition = [
{ name: 'id', type: 'inputSelect', label: 'Name', options: [], multiple: false },
...
setFormvalues(values){
let elements = [ { id:1, name: 'Pizza', }, { id:2, name: 'Hot Dogs', }];
this.formDefinition.find(el => el.name == 'id').options = elements;
this.form.setFormValues(values);
}