Xin vui lòng, bạn có thể giúp tôi không? Nó được cho là dễ dàng, nhưng tôi không thể tìm ra giải pháp. Có một hình thức với hai lựa chọn. Khi # select1 thay đổi, # select2 cần hiển thị dữ liệu theo giá trị của # select1. Ví dụ: nhận thành phố của mỗi tiểu bang. Loại:Sự kiện được chọn trong Angular2
//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];
}
}
này, tất nhiên, không hoạt động. XIN, bạn có biết làm thế nào nó nên được thực hiện? Đó là trong alpha28.