如何防止点击时选择标签?
How to prevent selecting tab on click?
如何防止选择标签添加其他标签?
下面我已经隔离了这个问题,如果我用加号单击选项卡然后它被选中,我想完全防止这种情况,只需单击并调用 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>
如何防止选择标签添加其他标签? 下面我已经隔离了这个问题,如果我用加号单击选项卡然后它被选中,我想完全防止这种情况,只需单击并调用 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>