Tag Archives: Error: [$compile:nonassign] Expression used with directive ‘uibTab’ is non-assignable

Error: [$compile:nonassign] Expression used with directive ‘uibTab’ is non-assignable

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 toactiveattribute 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-repeatif 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>