如何防止选择标签以添加其他标签? 下面我已经隔离了这个问题,如果我点击选项卡加上然后它被选中,我想完全阻止这个,只需点击并调用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>
答案 0 :(得分: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>