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