javascript - Selects' events in Angular2 -
please, can me? supposed easy, can't find solution. there form 2 selects. when #select1 changes, #select2 needs show data according value of #select1. example, cities of each state. kind of :
//html <select (change)="select2.getcities($event)" ng-control="userstate"> <option *ng-for="#state of states" [value]="state">{{state}}</option> </select> <select #select2 ng-control="usercity"> <option *ng-for="#city of cities" [value]="city">{{city}}</option> </select> //the component @component({ selector: 'user-management', appinjector: [formbuilder] }); @view({ templateurl: 'user-management.html', directives: [ngfor] }); export class usermanagement { constructor(fb: formbuilder){ this.userform = fb.group({ userstate: [], usercity: [] }); this.states = ['new york', 'pennsylvania']; this.cities = {'new york': ['albany', 'buffalo'], 'pennsylvania':['pittsburgh', 'philadelphia']}; } getcities($event){ return this.cities[$event.target.value]; } }
this, of course, doesn't work. please, know how should done? it's in alpha28.
great! found out how make work! :) thing missing, form model passed event. should this:
<form [ng-form-model]="userform"> <select (change)="select2.getcities($event, userform)" ng-control="userstate"> <option *ng-for="#state of states" [value]="state">{{state}}</option> </select>
Comments
Post a Comment