我正在使用Angular 2(TypeScript).
我想为新的选择做点什么,但是我在onChange()中得到的东西总是最后选择.我怎样才能获得新的选择?
<select [(ngModel)]="selectedDevice" (change)="onChange($event)">
<option *ngFor="#i of devices">{{i}}</option>
</select>
onChange($event) {
console.log(this.selectedDevice);
// I want to do something here for new selectedDevice, but what I
// got here is always last selection, not the one I just select.
}
Run Code Online (Sandbox Code Playgroud) 我有以下 HTML 模板
<input type="text" [(ngModel)]="mobile" (change)="mobileChanged()">
Run Code Online (Sandbox Code Playgroud)
这是我的 .ts
mobileChanged = () => {
console.log(this.mobile);
};
Run Code Online (Sandbox Code Playgroud)
在同一个元素中拥有ngModel和是错误的change吗?在我的情况下,mobileChanged当我输入输入时没有被调用。但是,当我检查 的值时mobile,它会正确更新。
这是 Angular 7。