Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

angularjs

tabs

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.

like image 719
Dario Quintana Avatar asked Dec 15 '15 22:12

Dario Quintana


2 Answers

It is better to update a scope variable and bind it to active 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 the plunkr

This also makes the implementation to be more re-usable than before (For instance, it can be easily used inside a ng-repeat if the need arises).

Reference: GitHub Issue

like image 144
Avijit Gupta Avatar answered Nov 08 '22 14:11

Avijit Gupta


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>
like image 44
gabrielgeo Avatar answered Nov 08 '22 12:11

gabrielgeo