Ng5-Dynamic Selectoption - , ,
template.html
//
<select (change)="countryChange($event)" >
<option>Select</option>
<option *ngFor="let c of countries" [ngValue]="c.country">{{ c.country }}</option>
</select>
<select (change)="statesChange($event)">
<option>Select</option>
<option *ngFor='let state of states' [ngValue]="state.name">{{ state.name }}</option>
</select>
<select >
<option>Select</option>
<option *ngFor='let city of cities' [ngValue]="city">{{ city }}</option>
</select>
component.ts
var = [{"": "", "": [{"": "", "": ["1", "2", "3"]}, {"": "", "": ["orc1", "oruc2", "oruc3"]}, {"name": "", "towns": ["3c1", "3c2", "3c3"] }]}, {"country": "Albania", "states": [{"name": "Korce", "towns": ["c1", "c2", "c3"]}, {"name": "Kukes", "towns": ["orc1", "oruc2", "oruc3"]}, {"name": "Lezhe", "towns": ["orc1", "oruc2", "oruc3"] }, {"name": "Shkoder", "towns": ["orc1", "oruc2", "oruc3"]}, {"name": "Tirane", "towns": ["orc1", "oruc2 "," oruc3 "]}]},
{"": "", "": []}
]
states= []; cities = [];
countryChange(e){
console.log(e.target.value)
this.countries.filter(element => {
if(element.country == e.target.value){
console.log(element.states[0],"first state")
this.states = element.states;
}
});
this.cities = []
}
statesChange(evt){
console.log(evt.target.value,this.states)
this.states.filter( element =>{
if(element.name == evt.target.value){
this.cities = element.cities;
}
})
}