0

他のタブを追加するためにタブを選択しないようにするにはどうすればよいですか? 以下で問題を切り分けました。プラス記号でタブをクリックして選択すると、これを完全に防止したいと思います。クリックして addNewTab() 関数を呼び出すだけです。

var app = angular.module('app', ['ui.bootstrap']);
app.controller('homeCtrl', function($scope) {

  $scope.tabs = [{
    name: "Tab 1",
    active: true
  }, {
    name: "Tab 2",
    active: false
  }, {
    name: "Tab 3",
    active: false
  }];

  $scope.addTab = function($event) {
    //$event.praventDefault();//not working
    //$event.stopPropagation();//not working
    console.log($event);
    console.log("do some stuff and call addNewTab()")
  };
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<script src="https://angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.12.1.min.js"></script>
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet" type="text/css" />

<div ng-app="app">
  <div ng-controller="homeCtrl">
    <tabset>
      <tab ng-repeat="tab in tabs" heading="{{tab.name}}" active="tab.active">
        {{tab.name}}
      </tab>
      <tab select="addTab($event)">
        <tab-heading>
          <i class="glyphicon glyphicon-plus-sign"></i>
        </tab-heading>
      </tab>
    </tabset>
  </div>
</div>

4

1 に答える 1

3

var app = angular.module('app', ['ui.bootstrap']);
app.controller('homeCtrl', function($scope) {

  $scope.tabs = [{
    name: "Tab 1",
    active: true
  }, {
    name: "Tab 2",
    active: false
  }, {
    name: "Tab 3",
    active: false
  }];

  $scope.addTab = function($event) {
    //$event.praventDefault();//not working
    //$event.stopPropagation();//not working
    console.log($event);
    console.log("do some stuff and call addNewTab()")
  };
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<script src="https://angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.12.1.min.js"></script>
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet" type="text/css" />

<div ng-app="app">
  <div ng-controller="homeCtrl">
    <tabset>
      <tab ng-repeat="tab in tabs" heading="{{tab.name}}" active="tab.active">
        {{tab.name}}
      </tab>
      <!-- <tab ng-click="addTab($event)"> !-->
      <li>
      <a ng-click="addTab($event)">
         <i class="glyphicon glyphicon-plus-sign"></i>
      </a>
      </li>
    </tabset>
  </div>
</div>

于 2015-03-06T08:56:14.407 に答える