bootstrap icon indicating copy to clipboard operation
bootstrap copied to clipboard

Using tabs causes $scope.$watch() functions to not get called

Open grosch opened this issue 12 years ago • 3 comments

 $scope.$watch('service', function () {
        alert("Changed");
 });

I use the above code in my controller and it's used with a select box, like so:

<select ng-model="service" ng-options="service.name for service in services">
 <option value="">-- Choose Service --</option>
</select>

Works perfectly. Now I put that select inside of a tab, like below, and the watch method is never again called.

<tabset>
<tab>
<select ng-model="service" ng-options="service.name for service in services">
 <option value="">-- Choose Service --</option>
</select>
</tab>
</tabset>

grosch avatar Jul 11 '14 00:07 grosch

I think I'm having a related issue...

I have a textarea that works fine outside of a tabset.

<textarea ng-model="testingTextArea"></textarea>

I can initialize testingTextArea like so:

$scope.testingTextArea = "Testing 123!";

... and the textarea will be prepopulated when I load the page and I can update it fine by editing the contents of the textarea.

If I move it inside a tabset...

<tabset>
 <tab>
  <textarea ng-model="testingTextArea2"></textarea>
 </tab>
</tabset>

It still prepopulates (one-way binding) but editing the contents of the textarea does not result in the model being updated.

Also, when I put watches on both...

$scope.$watch('testingTextArea', function() { alert('Changed'); });
$scope.$watch('testingTextArea2', function() { alert('Changed'); });

... the first one fires but the second one never does. My first thought was "maybe the tabs are creating a child scope," but if that were the case, wouldn't the textarea fail to prepopulate as well and not just fail to update the model on edit?

pipermatt avatar Sep 15 '14 20:09 pipermatt

Solution is here: #437

pipermatt avatar Sep 15 '14 21:09 pipermatt

Working as intended. See Understanding Scopes in the Angular.js Wiki.

chrisirhc avatar Oct 06 '14 08:10 chrisirhc