【发布时间】:2017-11-28 00:51:49
【问题描述】:
我有下一个 html:
<select [(ngModel)]="district" class="form-control" (change)="dsChange()">
<option disabled hidden [value]="undefined" >Ноҳия</option>
<option *ngFor="let dis of districts" [ngValue]="dis">{{dis.title}}</option>
</select>
我还有下一个组件
@Input() district: District;
ngOnChanges(changes: SimpleChanges) {
console.log("CHANGED")
}
dsChange(){
console.log(this.district);
}
我不明白为什么当我选择一些值时,dsChange 会触发正确的区值,但 ngOnChanges() 不是
【问题讨论】:
-
为什么要近距离投票?有人可以解释一下吗
-
这与组件之间的交互有关,这就是@Input和@Output的使用情况,在这里介绍:angular.io/guide/component-interaction
标签: angular angular2-template ngonchanges