Sunday, 25 August 2013

$scope is updated in view and not in controller for angularJs

$scope is updated in view and not in controller for angularJs

I have a scope defined in a controller as mentioned below :
$scope.countries = [{
name : 'India', code : 'IA'
}, {
name : 'Israel', code : 'IS'
}];
$scope.selectedCountries = [
'IA'
];
$scope.$watch('selectedCountries', function(newValue, oldValue) {
console.log ('data');
});
Now when the value changes in controller using select dropdown, the value
changes are reflected in view. But the watch is never called, as the scope
is not changed. Any idea why the scope is not updating ?

No comments:

Post a Comment