角2不给复选框的当前状态 [英] Angular 2 not giving current state of checkbox

查看:190
本文介绍了角2不给复选框的当前状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开始建立一个待办事项示例应用程序。我面临着一个奇怪的问题。
下面是HTML code的待办事项列表。在该列表中我设置为ngModel复选框,并触发一个更改事件也是如此。

I have started building an ToDo sample app. I am facing an strange issue. Below is the HTML code for the ToDo List. In that list i am setting ngModel for checkbox and firing an change event as well.

在这里输入的形象描述

code听的变化。我只打印出当前状态到控制台。

Code to listen the change. I am only printing the current state to console.

在这里输入的形象描述

看下面的图片可以看到的复选框的当前状态进行检查,但在控制台我得到复选框的previous状态。

Look at below image you can see the current state of the checkbox is checked but in console i am getting the previous state of the checkbox.

在这里输入的形象描述

请告诉我什么是有工作的正确途径。

Please tell me what is the correct approach to have that working.

推荐答案

这是一个已知的问题。

  • https://github.com/angular/angular/issues/3406,
  • https://github.com/angular/angular/issues/6311

有喜欢使用不同的解决方法 event.target.value 而不是从模型的价值。

There are different workarounds like using event.target.value instead of the value from the model.

这篇关于角2不给复选框的当前状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆