所以我试图在ng-repeat中为ng-click分配一个变量,如下所示:
<ul ng-repeat="stocksInPortfolio in ctrl.myPortfolio.stocksInPortfolio">
<li><a href ng-click="collapse = {{stocksInPortfolio.stock._id}}">{{stocksInPortfolio.stock.name | limitTo:10}}...</a></li>
<li>{{stocksInPortfolio.stock._id}}</li>
<h1>this collapse is {{collapse}}</h1>
</ul>
但它不起作用,我不确定我应该做什么来分配这个变量以使变量赋值动态化。
答案 0 :(得分:2)
您不需要在ng-click中使用括号{{ }}
!
<ul ng-repeat="stocksInPortfolio in ctrl.myPortfolio.stocksInPortfolio">
<li><a href ng-click="collapse = stocksInPortfolio.stock._id">{{stocksInPortfolio.stock.name | limitTo:10}}...</a></li>
<li>{{stocksInPortfolio.stock._id}}</li>
<h1>this collapse is {{collapse}}</h1>
</ul>