如何防止在单击时选择选项卡



如何防止选择选项卡来添加其他选项卡?下面我已经隔离了这个问题,如果我单击带有加号的选项卡,则它被选中,我想完全防止这种情况,只需单击并调用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>

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>

相关内容

  • 没有找到相关文章

最新更新