I am creating a form in HTML using ng-repeat to create form elements from an object in an area. I also use this object to create other elements outside of ng-repeat.
A simplified example looks like this in HTML:
<div ng-app="App"> <div ng-controller="Ctrl"> <div class="block1"> <form ng-repeat="(key, value) in test"> <label>{{key}}</label> <input ng-model="value" /> <p>{{value}}</p> </form> </div> <div class="block2"> <p> {{test.a}} </p> <p> {{test.b}} </p> </div> </div> </div>
and this is in JS:
angular.module('App', []); function Ctrl($scope) { $scope.test = { a:"abc", b:"def" } }
In this example, the text in block 2 is set to the initial values test.a and test.b Input values and <p> values inside the loop are also set to the initial value.
When I change the values inside the inputs, the <p> values inside the ng-repeat block are updated correctly, but the <p> tags in block 2 are not updated.
Why is this behavior? Does ng-repeat create its own isolated area? If so, how can I get the controller level area for updating? Also, can anyone explain the thinking behind this behavior and any of its benefits?
JSFiddle mapping problem
source share