Hi,
I went to develop update form,
so I must load values on init component:
Component:
ngOnInit(){
console.log(“init”);
this.selectedIntervention = this.navParams.data;
if(this.commonService.isEmptyObject(this.selectedIntervention)){
this.selectedClient = {}
this.selectedAdresse = {}
}
else{
this.selectedClient = this.selectedIntervention.int_client;
if(this.commonService.isEmptyObject(this.selectedClient)){
this.selectedAdresse = {}
this.adressesClient = []
}
else{
this.selectedAdresse = this.selectedIntervention.int_client.c_adresse;
this.getClientAdresse(this.selectedIntervention.int_client)
}
}
//new
if(this.commonService.isEmptyObject(this.selectedIntervention)){
this.formIntervention = this.formBuild.group({
int_client:[''],
int_adresse:['']
})
}
//update
else{
this.formIntervention = this.formBuild.group({
int_client:this.selectedClient,
int_adresse:this.selectedAdresse
})
}
console.log("selectedClient exist? "+ this.commonService.stringfyJson(this.formIntervention.contains("int_client"))+" value "+ this.commonService.stringfyJson(this.formIntervention.value) )
this.getAllClients()
}
in log selectedClient is not empty, but it’s not showed on load page !
HTML:
<form [formGroup]="formIntervention"> <ion-item> <ion-label floating>Client</ion-label> <ion-select formControlName="int_client" [(ngModel)]="selectedClient" required cancelText="Annuler" okText="Selectionner"> <ion-option [value]="null" >Aucun</ion-option> <ion-option *ngFor="let client of listClients" [value]="client" >{{client.c_nom}}</ion-option> </ion-select> </ion-item> </form>
However a simple string work perfectly