如何在ng-class中添加范围变量?是否可以将ng-class和class与范围变量结合起来?
我正在制作手风琴。所以我需要有独特的“isopen”类,比如isopne1,isopen2等等。每个手风琴都可以工作。
<accordion-heading>
{{list.name}}<i class="pull-right glyphicon" ng-class="{'icon-arrow-down-solid': isopen, 'icon-arrow-right-solid': !isopen}"></i>
</accordion-heading>
上面的代码是ng-repeat。我怎样才能设置这样的东西
ng-class="{'icon-arrow-down-solid': isopen{{list.value}}, 'icon-arrow-right-solid': !isopen{{list.value}}}"
答案 0 :(得分:1)
使用范围功能
ng-class="{'icon-arrow-down-solid': isopen(set.value), 'icon-arrow-right-solid': is_not_open(set.value)}"
答案 1 :(得分:0)
您的代码本身将正常工作,具体取决于您想要将css类添加到“i”元素的范围变量(isOpen标志)。在控制器中创建范围变量(isOpen标志)。然后取决于isOpen自动标记图标将更改
答案 2 :(得分:0)
<accordion close-others="oneAtATime">
<accordion-group ng-repeat="set in sets" ng-init="status = $first" is-open="status" class="witlistcontents">
<accordion-heading>
Name <i class="pull-right glyphicon" ng-class="{'icon-arrow-down-solid': status, 'icon-arrow-right-solid': !status}"></i>
</accordion-heading>
<accordion-body>
</accordion-body>
</accordion-group>
</accordion>
在ng-repeat中为手风琴提供图标类的正确方法