How to get selected value?


#1

HI,

I’m a new in Ionic and I can’t figure out how to get the selected value from object

here’s my .html

<ion-item>            
<ion-label floating>Kabupaten/Kota</ion-label>            
<ion-select (ionChange)="setDistrictValues(user.sCity)" [(ngModel)]="user.sCity.name" formControlName="sCity">             
<ion-option [value]="sCity" *ngFor="let sCity of city">{{sCity.name}} </ion-option>            
</ion-select>                      
</ion-item>

and my .ts

import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { AngularFireDatabase, FirebaseListObservable } from 'angularfire2/database';
import { AngularFireAuth} from 'angularfire2/auth';
import {Validators, FormBuilder, FormGroup } from '@angular/forms';
import { ToastController } from 'ionic-angular';
import { pasienbaru } from '../../models/todo';
import { PatoldPage } from '../patold/patold';

@IonicPage()
@Component({  
selector: 'page-editprofile', 
 templateUrl: 'editprofile.html',
})

export class EditprofilePage {
user : pasienbaru;  
patnewList : FirebaseListObservable<any>;  
pasienbaru = {   
 $key:'',    
name: '',    
jk:'',    
tl:'',    
myDate:'',    
ns:'',    
almt:'',    
sCity:'',    
sDistrict:'',    
sKlh:'',    
kp:'',    
no:'',    
agama:''  
};  
  
private todo : FormGroup;  
selectedKlhs: { id: number; name: string; city_id: number; district_id: number; }[];  
selectedDistricts: { id: number; name: string; city_id: number; city_name: string; }[]; 
klhs: { id: number; name: string; city_id: number; district_id: number; }[];  
districts: { id: number; name: string; city_id: number; city_name: string; }[];  
city: { id: number; name: string; }[];
  
constructor(private fire:AngularFireAuth, public navCtrl: NavController, public navParams: NavParams, public db: AngularFireDatabase,     private formBuilder: FormBuilder, public toastCtrl: ToastController) { 
this.initializeCity();
this.todo = this.formBuilder.group({     
 name: ['', Validators.required],     
 jk:[],     
 tl:['', Validators.required],     
 myDate:['', Validators.required],     
 ns:[],     
 almt:['', Validators.required],     
 sCity:['', Validators.required],     
 sDistrict:['', Validators.required],    
 kp:['', Validators.required],     
 no:['', Validators.required],     
 agama:['', Validators.required]  
  }); 
 }

initializeCity(){    
this.city = [       
 {id: 1, name: 'Jakarta Barat'},        
{id: 2, name: 'Jakarta Pusat'},        
{id: 3, name: 'Jakarta Selatan'},        
{id: 4, name: 'Jakarta Timur'},        
{id: 5, name: 'Jakarta Utara'},        
{id: 6, name: 'Kepulauan Seribu'},        
{id: 7, name: 'Kabupaten Lebak'},        
{id: 8, name: 'Kabupaten Pandeglang'},        
{id: 9, name: 'Kabupaten Serang'},        
{id: 10, name: 'Kabupaten Tangerang'},        
{id: 11, name: 'Kota Cilegon'},        
{id: 12, name: 'Kota Serang'},        
{id: 13, name: 'Kota Tangerang'},        
{id: 14, name: 'Kota Tangerang Selatan'}    
];    
}
 
 ionViewWillLoad() {    this.user = this.navParams.get('user');  }

if I use ion-input I can get the value from user.sCity.name. But it doesn’t work with ion-select