[英]how to use variable in ng-click and ng-repeat?
I opened a ng-repeat block and I want to use "id" as counter for define toggle button counter in ng-click like this: 我打开了一个ng-repeat块,我想使用“ id”作为在ng-click中定义切换按钮计数器的计数器,如下所示:
my code: 我的代码:
<div ng-repeat="line in linesList">
<a ng-click="'modal{{line.id}=!modal{{line.id}}'">{{line.id}}</>
</div>
my result is like this: 我的结果是这样的:
ng-click="'modal1=!modal1'"
but I need this: 但我需要这个:
ng-click="modal1=!modal1"
You can use an object 'modal', not multiple variables modal1, modal2, etc. 您可以使用对象“模态”,而不是多个变量modal1,modal2等。
In your controller : 在您的控制器中:
$scope.modal = {}
$scope.toggleModal = function(id) {
$scope.modal[id] = !$scope.modal[id]
}
And then: 接着:
<div ng-repeat="line in linesList">
<a ng-click="toggleModal(line.id)">{{line.id}}</>
</div>
See example here : http://codepen.io/thierry36t/pen/QGqPyj 在此处查看示例: http : //codepen.io/thierry36t/pen/QGqPyj
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.