In a parent controller scope, I have defined selectedItem
which is set to \'x\'. Then in the child scope, I have defined selectedItem
using ngModel
I've noticed in similar cases that AngularJS does not watch selectedItem
properly. The only way I found is to initialize selectedItem
with an entry from the items
array. Try the following:
function CtrlA($scope) {
$scope.items = ['x', 'y'];
$scope.selectedItem = $scope.items[0];
}
If you try to bind to a primitive declared on parent scope, then the selectedItem in child scope will effectively shadow the property of the same name in the parent scope.
In this case there are 3 choices
More about it on https://github.com/angular/angular.js/wiki/The-Nuances-of-Scope-Prototypal-Inheritance
You can find the updated fiddle using the first approach at http://jsfiddle.net/sudhh/XU2rP/1/
function CtrlA($scope) {
$scope.items = ['x', 'y'];
$scope.ref = {
selectedItem: 'x'
};
}