0

So I'm really confused with the following concept and hope someone can clear it up for me. Consider the following template code:

<test-dir val="val"></test-dir>

Assume test-dir has the following isolated scope:

scope:{ val : '='}

My understanding that this achieves a 2-way binding between the $scope.val variable inside the test-dir directive and the global variable $scope.val. So if I change the value of either one, the other one would be affected.

However, consider now I have the following template code:

<div ng-repeat="(index, val) in values">
  <test-dir index="index" val="val"></test-dir>
</div>

and the following isolated scope:

scope:{
  index:'=', 
  val : '='
}

Suddenly index and val are no longer 2-way bound. So each one of my test-dir directive has its own index and val, and changing the variables locally won't effect anyone else. Why?

1 Answer 1

1

ng-repeat creates new child scopes, so each test-dir having its own index and val is working as intended.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.