这里我有代码:
<ul ng-controller="Modalcontrol" class="card_ul">
<li ng-repeat="item in list">
{{item.name }}
<p>
<span class="yellow" align="left" ng-repeat="labels in item.labels" ng-show="filter_card_id == labels.id" >
{{ labels.id }}
</span>
#{{ item.card_id }}
</p>
</li>
</ul>
在此ng-show =&#34; filter_card_id == labels.id&#34;代码工作正常,但我想应用此节目并隐藏到此父列表。如何?
答案 0 :(得分:1)
使用$parent
ng-show="filter_card_id == $parent.labels.id"
答案 1 :(得分:0)
您可以在父列表中进行过滤,如下所示:
angular.module('ExampleApp', [])
.controller('ExampleController', function() {
this.list = [{
id: 1,
labels: [{
id: 11
}, {
id: 12
}]
}, {
id: 2,
labels: [{
id: 21
}, {
id: 22
}]
}, {
id: 3,
labels: [{
id: 31
}, {
id: 32
}]
}];
this.filter = {
id: undefined
};
});
&#13;
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.8/angular.js"></script>
<div ng-app="ExampleApp">
<div ng-controller="ExampleController as vm">
<label>
Filter
<input type="number" ng-model="vm.filter.id" />
</label>
<ul ng-repeat="item in vm.list|filter:{labels:{id:vm.filter.id?vm.filter.id:undefined}}:true">
<li>{{item.id}}
<ul ng-repeat="label in item.labels|filter:{id:vm.filter.id?vm.filter.id:undefined}:true">
<li>{{label.id}}</li>
</ul>
</li>
</ul>
</div>
</div>
&#13;
jsfiddle上的实例。