HTML
<ul class="column__list">
<li class="column__list--item" ng-repeat="task in tasks | orderBy:'name':false" data-ng-class="{active:taskIndex=={{$index}}}">
<div class="column__list--expand fa" ng-click="expand = !expand" ng-class="{'fa-chevron-down': !expand, 'fa-chevron-up': expand}"></div>
<div class="column__list--actions slide" ng-show="expand">
{{ children }}
</div>
</li>
</ul>
角
angular.module('App.animate', [])
.animation('.slide', function() {
var NgHideClassName = 'ng-hide';
return {
beforeAddClass: function(element, className, done) {
if(className === NgHideClassName) {
jQuery(element).slideUp(done);
console.log('0');
}
},
removeClass: function(element, className, done) {
if(className === NgHideClassName) {
jQuery(element).hide().slideDown(done);
console.log('1');
}
}
}
});
我有上面的内容,当点击div时会滑动,当再次点击时会滑动.column__list--expand
如果我只希望一次展示一个li
并同时更新ng-class
该怎么办?
答案 0 :(得分:1)
将模板更改为:
<div ng-app="testApp" ng-controller="testController">
<ul class="column__list">
<li class="column__list--item" ng-repeat="task in tasks | orderBy:'name':false" data-ng-class="{active:taskIndex=={{$index}}}">
<div class="column__list--expand fa" ng-click="$parent.selectedTask = $parent.selectedTask == task ? null : task" ng-class="{'fa-chevron-down': $parent.selectedTask!=task, 'fa-chevron-up': $parent.selectedTask==task}">{{ task.title }}</div>
<div class="column__list--actions slide" ng-show="$parent.selectedTask==task">
{{ task.description }}
</div>
</li>
</ul>
</div>