nicker
nicker

Reputation: 487

Separate/isolate $scope variable with same name in 2 different controllers that are in use concurently

I have a $scope.test.name in both 'test1' controller and 'test2' controller.

The backdrop:

the issue:

Is there a way to isolate or cut off relation of $scope.test.name from both controller beside giving a different name?

Upvotes: 0

Views: 353

Answers (2)

Alexander
Alexander

Reputation: 3245

You can use the controller as syntax:

<div ng-controller="Test1Ctrl as test1">
  {{ test1.test.name }}
  <div ng-controller="Test2Ctrl as test2">
    {{ test2.test.name }}   
  </div>
</div>

Upvotes: 2

Vikash Kumar
Vikash Kumar

Reputation: 1718

that's because of parent child relationship and test2 comes inside test1 so it will reflect the changes but vice-versa it will not work i will recommend you using directive with isolated scope.

you can refer here https://thinkster.io/egghead/understanding-isolate-scope

Upvotes: 1

Related Questions