单击两次ng-click,两个类别不同的​​ng-repeat依赖选项

时间:2015-04-17 16:07:43

标签: javascript html css angularjs

我有两个按钮,应该删除ng-repeat上的div,但是根据按钮必须在效果中添加一个自定义css类,具体取决于css更改的选项。

如果我点击按钮应该在第一张卡片类上添加拒绝或接受并删除卡片,现在我通过.pop()删除卡片,但不添加课程。如果我删除$ scope.matches.pop();添加类但显然不删除卡,如果我保留该行,请不要添加css类。

Plunker:http://plnkr.co/edit/go54DQMsPdsRcssLeZZ5?p=preview

我正在使用以下代码:

<td-card ng-class="{reject : rejectShow(match), accept : acceptShow(match)}" ng-repeat="match in matches track by $index" class="cards card-{{$index}}" > 
    <div class="content">content</div>
</td>

<button class="button" ng-click="reject(match)">
    button reject
</button>

<button class="button" ng-click="accept(match)">
    button accept
</button>

Code AngularJS:

var shownAccept = false
var shownReject = false
var className = 'initClass';

$scope.accept = function(match) {
    console.log('accept button')
    $scope.matches.pop();
    shownAccept = match;
}

$scope.reject = function(match) {
    console.log('reject button')
    $scope.matches.pop();
    shownReject = match;
}

$scope.rejectShow = function(match) {
    return angular.equals(shownReject, match);
}

$scope.acceptShow = function(match) {
    return angular.equals(shownAccept, match);
}

PS。我正在寻找不使用jquery的选项

1 个答案:

答案 0 :(得分:1)

使用变量$scope.selectedIndex

每当您点击更新时:$scope.selectedIndex = $index