繁体   English   中英

Angular js中的ng-repeat

[英]ng-repeat in angular js

<td >
    <div class="form-group" ng-repeat="K in datavalue">
        <div ng-if="(p.id == K.emp_id && T.id == K.component_id)">    
            {{K.amount}}
        </div>
    </div>  

    <input type="text" placeholder="Enter value"  class="form-control" name="cvalue"   ng-model="T.cvalue"  required/> 
</td>

在这里我做了一个循环,其中还检查了一个表达式。
如果为真,则显示值,否则显示输入框。 但我的问题是,如果我在循环中插入输入框,那么如果表达式失败,输入框将显示数字。
否则,如果表达式为true和文本框一起显示{{K.amount}}的值。

我该如何解决这个问题?

ng-if创建一个隔离的作用域。 尝试改用ng-show ,这样输入元素上的ng-model将绑定到正确的范围:

<div ng-if="(p.id == K.emp_id && T.id == K.component_id)">
    {{K.amount}}
    <input type="text" placeholder="Enter value" class="form-control" name="cvalue" ng-model="T.cvalue" required/> 
</div>

使用 ng-show 和 ng-hide

<div class="form-group" ng-repeat="K in datavalue">
    <div ng-show="(p.id == K.emp_id && T.id == K.component_id)">
       {{K.amount}}
    </div>
    <div ng-hide="(p.id == K.emp_id && T.id == K.component_id)">
       <input type="text" placeholder="Enter value"  class="form-control" name="cvalue"   ng-model="T.cvalue"  required/> 
    </div>
</div>  

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM