簡體   English   中英

Angular ngRepeat折疊div

[英]Angular ngRepeat collapse div

當我在ng-repeat中單擊一個div時,它將運行一個函數。 它會打開該div,以便您獲取有關它的更多信息。 當我在ng-repeat中單擊另一個div時。 它將關閉所有其他div並打開所選的div。

我該怎么說呢?當我打開同一個div時,它也會關閉該div,以便所有div都關閉。

這是我的代碼:

角度:

   $scope.setSelected = function(index) {
        $scope.selectedIndex = index;
    };

的HTML:

ng-click="setSelected($index);" ng-class="{ 'selectedBox': $index == selectedIndex }"

用這個:

$scope.setSelected = function(index) {
        $scope.selectedIndex = $scope.selectedIndex == index ? -1 : index;
};

您可以只在setSelected添加檢查?

$scope.setSelected = function(index) {
    $scope.selectedIndex = $scope.selectedIndex === index ? null : index;
};

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM