[英]How to hide all other elements when a sub-element of one is clicked
我需要能夠通過單擊也由ng-repeat創建的其他元素來隱藏由ng-repeat
動態生成的元素。 HTML示例:
<div ng-repeat="thing in things" ng-show="!displayId || displayId == 'thing.id'">
<button ng-click="displayId = 'thing.id'">Click me!</button>
</div>
初始顯示效果很好,因為在單擊按鈕之前未指定displayId
,但是我希望發生的事情是將displayId
設置為我單擊的任何按鈕的thing.id
,一旦設置,所有其他div都會被隱藏。 但是,什么也沒有發生。
有沒有辦法做到這一點? 我試圖不使用任何jquery並以純角度的方式執行此操作。
因此,根據您提供的額外細節,您可以在ng-repeat
上使用filter
。
<div ng-repeat="thing in things | filter:{id: selectedThingId}">
<button ng-click="setSelectedThing(thing.id)">Click me!</button>
</div>
在您的控制器中:
$scope.selectedThingId;
$scope.setSelectedThingId = function setSelectedThingIdFn(thingId) {
$scope.selectedThingId = thingId;
}
<iframe style="width: 100%; height: 600px" src="http://embed.plnkr.co/tpMSLcpEGkoWx4eGDcHo/preview" frameborder="0" allowfullscren="allowfullscren"></iframe>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.