I am new to Angular 2 and I've recently been trying the two-way binding. I have the following code:
template.html
<select [(ngModel)]="val" (change)="onChanged()">
<option>1</option>
<option>2</option>
<option>1</option>
</select>
component.ts
..//other code definitions here
export class MyComponent{
val: number = 1; //edited this
onChanged(){
console.log(this.val);
}
}
The problem is when the selected value on the dropdown changes, the value outputted on the console is still the previous value. It only updates after I select again another value, but the printed value was still the previously selected value. So it's like delayed by one selection.
Hope anyone can help.
Thanks.