bootstrap btn-group中的angularjs toggle类

时间:2017-11-08 20:55:02

标签: javascript angularjs twitter-bootstrap

我有一组按钮:

<div class="btn-group">
    <button class="btn btn-primary" ng-click="filter_emails()"><span class="ion-home mr-2"></span>All</button>
    <button class="btn btn-outline-primary" ng-click="filter_emails('new')"><span class="ion-plus-circled mr-2"></span>New</button>
    <button class="btn btn-outline-primary" ng-click="filter_emails('inbox')"><span class="ion-archive mr-2"></span>Inbox</button>
    <button class="btn btn-outline-primary" ng-click="filter_emails('shielded')"><span class="ion-paper-airplane align-middle mr-2"></span>Shielded</button>
</div>

和ng-click功能如下:

$scope.filter_emails = function(category) {
    if (category === "inbox") {
        $scope.grouped = group(inbox($scope.emails));
    } else if (category === "shielded") {
        $scope.grouped = group(shield($scope.emails));
    } else if (category === "new") {
        $scope.grouped = group(is_new($scope.emails));
    } else {
        $scope.grouped = group($scope.emails);
    }
}

我想要实现的目标是添加&b; btn-primary&#39; / remove&#39; btn-outline-primary&#39;点击按钮并添加“&btn-outline&#39; / remove&#39; btn-primary&#39;从之前选择的按钮。

我对angularjs很陌生,所以我不知道如何做到这一点,我想用jQuery来抵制任何增加:)

2 个答案:

答案 0 :(得分:1)

您可以通过存储点击按钮轻松完成此操作,更新您的方法,如

NewRng = "=" & sht & "!" & x.Address & ":" & y.Address

Worksheets(sht).ChartObjects(cht).Activate
ActiveChart.FullSeriesCollection(sers).Values = NewRng

在你的html中,你只需使用Sheets(sht).ChartObjects(cht).Activate ActiveChart.SeriesCollection(sers).Values = "='" & sht & "'!" & ActiveCell.Address & ":" & ActiveCell.Offset(0, -5).Address 来相应地更新课程,

$scope.filter_emails = function(category) {
    $scope.selectedButton = category;
    if (category === "inbox") {
        $scope.grouped = group(inbox($scope.emails));
    } else if (category === "shielded") {
        $scope.grouped = group(shield($scope.emails));
    } else if (category === "new") {
        $scope.grouped = group(is_new($scope.emails));
    } else {
        $scope.grouped = group($scope.emails);
    }
}

答案 1 :(得分:1)

创建指令并将其放入HTML

HTML

<div class="btn-group">


   <button class="btn btn-primary" ng-click="filter_emails()" get-siblings><span class="ion-home mr-2"></span>All</button>
    <button class="btn btn-outline-primary" ng-click="filter_emails('new')" get-siblings><span class="ion-plus-circled mr-2"></span>New</button>
    <button class="btn btn-outline-primary" ng-click="filter_emails('inbox')" get-siblings><span class="ion-archive mr-2"></span>Inbox</button>
    <button class="btn btn-outline-primary" ng-click="filter_emails('shielded')" get-siblings><span class="ion-paper-airplane align-middle mr-2"></span>Shielded</button>
</div>

的Javascript

yourApp.directive('getSiblings', function() {
   return {
      scope: true,
      link: function(scope,element,attrs){
        element.bind('click', function() {
            element.addClass('btn-primary');
            element.removeClass('btn-outline-primary');
            element.siblings('button').addClass('btn-outline');               
            element.siblings('button').removeClass('btn-primary');               
         }
      }
   }
});