ng-if 在 ng-repeat 中不起作用
ng-if inside ng-repeat won't work
我的 HTML 上有这段代码,我用 Angular:
填充
<table id="myTable">
<tr>
<th>Id</th>
<th>desc</th>
<th>prod kg</th>
<th>index</th>
</tr>
<tr ng-repeat="x in maq" ng-if="{{ x.index }}=='0'" id="{{ x.index }}">
<td style="border: 1px solid black;">{{ x.codigo }}</td>
<td style="border: 1px solid black;">{{ x.desc }}</td>
<td style="border: 1px solid black;">{{ x.prod_24_h_kg }}</td>
<td style="border: 1px solid black;">{{ x.index }}</td>
</tr>
</table>
到目前为止没有问题。但是,如您所见,我想为每一行制作和 ng-if,让我们说:
{{ x.index }}=='0'
我不想显示该行。我尝试了很多“”和“”的组合,但都没有成功。有人看到解决方案了吗?
无需在 ng-if
指令中使用插值 {{}}
指令,它直接采用将根据当前范围进行计算的表达式。
ng-if="x.index ==0"
实现相同目的的另一种选择是使用过滤器。
ng-repeat="x in maq | filter: {index: 0} as filterdMaq"
同样的过滤事情可以发生在控制器内部,这也有助于提高性能。
$http.get('data.json').then(function(response){
$scope.dataCopy = response.data; //this is original copy of an maq.
//filtered maq
$scope.maq = $filter('filter')(angular.copy($scope.dataCopy), { index: 0}, true);
});
您不需要使用{{ }}。只需打印 x.index=='0'
我的 HTML 上有这段代码,我用 Angular:
填充<table id="myTable">
<tr>
<th>Id</th>
<th>desc</th>
<th>prod kg</th>
<th>index</th>
</tr>
<tr ng-repeat="x in maq" ng-if="{{ x.index }}=='0'" id="{{ x.index }}">
<td style="border: 1px solid black;">{{ x.codigo }}</td>
<td style="border: 1px solid black;">{{ x.desc }}</td>
<td style="border: 1px solid black;">{{ x.prod_24_h_kg }}</td>
<td style="border: 1px solid black;">{{ x.index }}</td>
</tr>
</table>
到目前为止没有问题。但是,如您所见,我想为每一行制作和 ng-if,让我们说:
{{ x.index }}=='0'
我不想显示该行。我尝试了很多“”和“”的组合,但都没有成功。有人看到解决方案了吗?
无需在 ng-if
指令中使用插值 {{}}
指令,它直接采用将根据当前范围进行计算的表达式。
ng-if="x.index ==0"
实现相同目的的另一种选择是使用过滤器。
ng-repeat="x in maq | filter: {index: 0} as filterdMaq"
同样的过滤事情可以发生在控制器内部,这也有助于提高性能。
$http.get('data.json').then(function(response){
$scope.dataCopy = response.data; //this is original copy of an maq.
//filtered maq
$scope.maq = $filter('filter')(angular.copy($scope.dataCopy), { index: 0}, true);
});
您不需要使用{{ }}。只需打印 x.index=='0'