<div class="col-sm-4 col-xs-4" ng-repeat="(id, object) in objects">
<button type="primary"
ng-click="add(id)"
ng-hide="id.plz" style="color: cyan;">Add</button>
</div>
$scope.add = function(id){
// some function;
$scope.objects[id].plz = true;
}
知道为什么它不起作用?
答案 0 :(得分:2)
<div class="col-sm-4 col-xs-4" ng-repeat="(id, object) in objects">
<button type="primary" ng-hide="objects[id].plz" ng-click="add(id)" style="color: cyan;" >Add</button>
<div>
此处ng-hide="id.plz"
id是索引,因此没有id.plz
详细了解ng-hide
和替代here
答案 1 :(得分:1)
如果您想在ng-repeat中有条件地隐藏按钮,请使用ng-hide,ng-show(如果您有可能隐藏并稍后显示)或ng-if(如果它是&#39; sa一次隐藏按钮)。
ng-hide采用布尔值并相应地显示/显示。在你的情况下,你的ng-hide总是被证明是真的,所以你无法隐藏。只需写下你的ng-hide中所需的条件来隐藏你的按钮
答案 2 :(得分:1)
点击按钮时隐藏按钮this fiddle:
<div ng-controller="MyCtrl">
<div ng-repeat="user in data">
{{ user.name}}
<button ng-hide="hide[$index]" ng-click="add();hide[$index] = true;">
Add
</button>
</div>
</div>
var myApp = angular.module('myApp',[]);
myApp.controller('MyCtrl', function ($scope) {
$scope.add = function () {
console.log('add');
}
$scope.data = [{
name: 'frank'
},{
name: 'peter'
},{
name: 'melanie'
},{
name: 'sven'
},{
name: 'basti'
},{
name: 'edjuh'
}];
});