I am facing an issue with the communication between a child controller and a parent controller. I have a function that adds data to a parent array which is used in an ng-repeat directive.
Although the parent array gets updated correctly and its length is displayed accurately in the parent controller, the ng-repeat directive fails to refresh.
<div ng-controller="parentCtrl">
This shows {{shared.arr.length}} <br/>
This also shows {{shared.arr|json}} <br/>
<div ng-repeat="a in shared.arr">
{{a}} This does not update, it continues to display old data.
</div>
<section ng-contoller="childCtrl">
<button ng-click="test()">Test</button>
</section>
</div>
angular.module('testApp')
.controller('parentCtrl', function ($scope) {
$scope.shared = {arr:[1,2]};
});
.controller('childCtrl', function ($scope) {
$scope.test = function(){$scope.shared.arr.push(4);}
});