[英]Angular ngRepeat collapse div
When I click on one of the divs inside my ng-repeat it runs a function. 当我在ng-repeat中单击一个div时,它将运行一个函数。 And it opens that div so that you get more information about it.
它会打开该div,以便您获取有关它的更多信息。 When I click on another div inside my ng-repeat.
当我在ng-repeat中单击另一个div时。 It will close all the other divs and open the selected one.
它将关闭所有其他div并打开所选的div。
How can I say when I click on the same div when its opend it also close that div so that all the divs are closed. 我该怎么说呢?当我打开同一个div时,它也会关闭该div,以便所有div都关闭。
Here is my Code: 这是我的代码:
Angular: 角度:
$scope.setSelected = function(index) {
$scope.selectedIndex = index;
};
html: 的HTML:
ng-click="setSelected($index);" ng-class="{ 'selectedBox': $index == selectedIndex }"
Use this: 用这个:
$scope.setSelected = function(index) {
$scope.selectedIndex = $scope.selectedIndex == index ? -1 : index;
};
You could just add a check in setSelected
? 您可以只在
setSelected
添加检查?
$scope.setSelected = function(index) {
$scope.selectedIndex = $scope.selectedIndex === index ? null : index;
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.