TAGS :Viewed: 7 - Published at: a few seconds ago

[ $rootScope's databinding could not get the right value ]

I write a demo to show this problem, when you change the select value, curTpl will change. However, if you want to see the value of curTpl, the value don't change!

http://plnkr.co/edit/pm1pIomr625WkvpHrggc?p=preview

Answer 1


You need to inject $scope rather than $rootScope into the controller like this

controller('testCtrl', ['$scope', testCtrl]);

AngularJS creates a child scope automatically when compiled HTML template is executed. So the ng-model used in the template is in child scope. Since you tried to access the data in the controller, you have to access to the the same child scope as the template.