角度js中的ng-repeat

时间:2015-11-27 11:01:47

标签: javascript html angularjs

<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}}且文本框合在一起,它将显示true的值。

我该如何解决这个问题?

2 个答案:

答案 0 :(得分:0)

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>

答案 1 :(得分:-1)

使用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>  
相关问题