Reputation: 991
I have next 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>
Also I have next component
@Input() district: District;
ngOnChanges(changes: SimpleChanges) {
console.log("CHANGED")
}
dsChange(){
console.log(this.district);
}
And I can not understand why when I select some value dsChange is triggered with correct value of district, but ngOnChanges() not
Upvotes: 3
Views: 7809
Reputation: 11
It's not calling the onChanges
even though the variable is local to the component.I created a plukr for this:
https://plnkr.co/edit/lsqyeZ8aiBpylciOQxnU?p=preview
Upvotes: 1
Reputation: 40896
ngOnChanges
is called when a component's data-bound input properties change. In your case, it would be called if the parent component sets a new value for @Input() district
.
ngOnChanges()
Respond when Angular (re)sets data-bound input properties...Called before ngOnInit() and whenever one or more data-bound input properties change.
Upvotes: 6