Angular2:2路绑定更新不及时的数据下划线 [英] Angular2: 2 way binding not updating the underline data

查看:161
本文介绍了Angular2:2路绑定更新不及时的数据下划线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这我猜想这应该工作:

  @Component ...
    ...
    <div *ngFor="#item of m_checkboxes">
        <Input #checkInputs type="checkbox" [(value)]="item.value">
    </div>
    ...

  constructor(){
    var self = this;
    setInterval(()=>{
        console.log(self.m_checkboxes);
    },3000)
}

但检查定时器,当我点击该复选框(并等待3+秒)下划线数据结构不变异...

but inspecting the timer, the underline data structure is not mutating when I click on the checkbox (and wait 3+ sec)...

我知道我可以使用ngModel但我试图让[(丙)的工作,而不是ngModel。

I know I can use ngModel but I am trying to get [(prop)] working instead of ngModel.

我unlderline数据基本上是一个数组:

My unlderline data is basically an array of:

    this.m_checkboxes = [{checked: true}, {checked: true}];

我几乎认为这是不支持,因为我无法找到一个例子网上的2路与非ngModel绑定:/

I almost think this is not supported as I couldn't find a single example online of 2 way binding with non ngModel :/

想法?

关于

肖恩

推荐答案

首先,你使用了错误的属性。它应该是检查,而不是

First, you're using the wrong property. It should be checked, not value.

二,有刚刚尝试过了,看来你确实有使用 ngModel 。双向绑定语法在一般的方式规定不具体到ngModel,但检查属性没有关联的 checkedChange 事件将需要为它工作。

Second, having just now tried it out, it seems that you actually have to use ngModel. The two-way binding syntax is specified in a general way not specific to ngModel, but the checked property does not have the associated checkedChange event that would be needed for it to work.

这篇关于Angular2:2路绑定更新不及时的数据下划线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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