Angular 2更改事件-模型更改 [英] Angular 2 change event - model changes
本文介绍了Angular 2更改事件-模型更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
更改模型后如何获取值? (change)
事件确实在模型更改之前触发.我不想使用event.target.value
How can I get the values after a model has changed? The (change)
event does fire before the model change. I do not want to use event.target.value
<input type="checkbox" (change)="mychange(event)" [(ngModel)]="mymodel">
public mychange(event)
{
console.log(mymodel); // mymodel has the value before the change
}
推荐答案
<罢工> 这是一个已知问题.当前,您必须使用问题中所示的解决方法.
That's a known issue. Currently you have to use a workaround like shown in your question.
这正在按预期方式工作.发出更改事件ngModelChange
([(ngModel)]
的(...)
部分尚未更新绑定模型:
This is working as intended. When the change event is emitted ngModelChange
(the (...)
part of [(ngModel)]
hasn't updated the bound model yet:
<input type="checkbox" (ngModelChange)="myModel=$event" [ngModel]="mymodel">
另请参见
- https://github.com/angular/angular/issues/3406,
- https://github.com/angular/angular/issues/6311
这篇关于Angular 2更改事件-模型更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文