NG-改变并不吴重复生成的表行工作 [英] ng-change does not work in the table row generated by ng-repeat

查看:140
本文介绍了NG-改变并不吴重复生成的表行工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的表行。

在这里输入的形象描述

行由低于code产生的。

The row is generated by below code.

<tr ng-init="cacheChanged">
    <td>Expiration Period</td>
    <td ng-repeat="system in tableData.regions[0].systems">
        <input type="text" ng-model="system.cacheDuration" ng-change="cacheChanged=true">
        <span>h</span>
    </td>
    <td>
        <button type="button" ng-click="saveCache()" ng-disabled="!cacheChanged">Save</button>
    </td>
</tr>

在任何改变的四个值,保存按钮应该被启用。但是,它仍然被禁用所有的时间。任何人都知道这是为什么?在此先感谢!

When any of the four values changed, the save button is supposed to be enabled. However, it is still disabled all the time. Anyone knows why? Thanks in advance!

推荐答案

在你的情况,你应该使用 $ parent.cacheChanged 而不是 cacheChanged 变量。由于 NG-重复确实为每个循环创建子范围,同时呈现DOM。总之 NG-重复中的 cacheChanged 变量是不一样的 cacheChanged 按钮使用那里。

In your case you should use $parent.cacheChanged instead of cacheChanged variable. As ng-repeat does create child scope for each loop while rendering DOM. In short the cacheChanged variable inside ng-repeat is not same as that of cacheChanged used there on button.

标记

<td ng-repeat="system in tableData.regions[0].systems">
    <input type="text" ng-model="system.cacheDuration" ng-change="$parent.cacheChanged=true">
    <span>h</span>
</td>

有更好的方式来为它去将使用点规则在定义 NG-模型,看这方面的详细回答这里

There is better way to go for it will be using Dot rule while defining ng-model, look at this detailed answer here.

这篇关于NG-改变并不吴重复生成的表行工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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