In my Ionic 3 project, I have successfully implemented a dynamic select option. However, I am facing an issue where I can only retrieve either the ID or the Name value of the selected option from the server, but not both.
I have tried using JSON.parse and accessing id.value and name.value in the options, but it seems I am only able to capture the first value. Can someone please help me with this? Here is the code snippet:
<ion-list >
<ion-item class="list-but">
<ion-label>Tipo de Ambiente</ion-label>
<ion-select
[(ngModel)]="idType"
multiple="false"
cancelText="Cancelar"
okText="Ok"
>
<ion-option
*ngFor="let type of type_environment"
[value]="type.id"
#name
>{{ type.name }}</ion-option
>
</ion-select>
</ion-item>
</ion-list>
<button ion-button block (click)="insert()">Salvar</button>
``public type_environment = new Array<any>();
public idType: number = 0;
public nameType: string = "name";
private userData: any;`
insert() {
this.userData = this.user.getUserData();
let body = {
name: this.nameType,
id_type: this.idType,
id_unity: this.navParams.get("id.unidade")
};
console.log("name:", this.idType);
this.route.postData("/ambiente", body).subscribe(
data => {
let response = data as any;
let ret = JSON.parse(response._body);
if (ret.insertId) {
this.navCtrl.popToRoot();
} else {
console.log(ret);
}
},
error => {
console.log(error);