I’ve a simple scenario. Two tabs, tab 1 & 2. Need to be able to select Tab 1 via link.
Html:
<p>
<a href="#" ng-click="selectTab1()">
<span class="glyphicon glyphicon-plus-sign"></span> Select TAB 1
</a>
</p>
<uib-tabset>
<uib-tab heading="Tab 1" active="activeTab==true" ng-click="clickTab1()">
Content 1
</uib-tab>
<uib-tab heading="Tab 2 (default)" active="activeTab==false" ng-click="clickTab2()">
Content 2
</uib-tab>
</uib-tabset>
Controller code here:
$scope.activeTab = false;
$scope.selectTab1 = function() {
$scope.activeTab = true;
}
$scope.clickTab1 = function() {
$scope.activeTab = true;
}
$scope.clickTab2 = function() {
$scope.activeTab = false;
}
Plunker is here:http://plnkr.co/edit/5yBHmXZBHyWYZEtmshad?p=info
When clicking in Tab 1 or 2, I’m getting the following error:
Error: [$compile:nonassign] Expression 'activeTab==true' used with directive 'uibTab' is non-assignable!
I could change this expression'activeTab==true'
to a shorter way like ‘activeTab’ but It doesn’t seems to be working.
2 Answers
1、It is better to update a scope variable and bind it toactive
attribute of your tabs:
$scope.activeTab = [];
$scope.selectTab1 = function(index) {
$scope.activeTab[index] = true;
};
$scope.clickTab = function(index) {
$scope.activeTab[index] = true;
};
In your view:
<uib-tab heading="Tab 1" active="activeTab[0]" ng-click="clickTab(0)">
Content 1
</uib-tab>
<uib-tab heading="Tab 2 (default)" active="activeTab[1]" ng-click="clickTab(1)">
Content 2
</uib-tab>
I have updated theplunkr
This also makes the implementation to be more re-usable than before (For instance, it can be easily used inside ang-repeat
if the need arises).
Reference:GitHub Issue
2、For the latest version of uib (2.4.0) it should be like this:
In controller:
$scope.activeTab = 1;
In view:
<uib-tabset active="activeTab">
<uib-tab index="0" heading="Tab 1">
Content 1
</uib-tab>
<uib-tab index="1" heading="Tab 2">
Content 2
</uib-tab>
</uib-tabset>
Similar Posts:
- Reloading the current routing page using UI router in angularjs
- How to Solve Datatable field value is empty Error
- Sublime text Upload FTP Error: failure (Disconnected – possible PASV mode error, try setting ftp_passive_mode to false in sftp-config.json)
- Solve the problem of style in cannot read property ‘style’ of null
- Solve the problem of style in cannot read property ‘style’ of null
- iOS Presenting view controllers on detached view controllers is discouraged
- Syntax error reported by JavaScript function: expected expression, got ‘;’
- When using angularjs procedure, track by $index of NG repeat
- [Solved] Elasticsearch Error: “java.lang.IllegalArgumentException: Rejecting mapping update to [xxx] as the final mapping would have more than 1 type: [_doc, log]””
- Getting Started with AngularJS 1.5 and ES6: part1