Simple example:
<body ng-app="testApp">
<form name="myForm" id='CtrlHost' ng-controller="Ctrl">
<input type="Button" value="Change Inside Angular" ng-click="ChangeIt()" />
<input type="Button" value="Change Outside Angular" onclick="OutsideAngularChange()" />
</form>
</body>
angular.module('testApp', [])
.controller('Ctrl', function($scope, MyService) {
var NewPropValue = 1;
$scope.ChangeIt = function () {
alert("scope.changeit called");
NewPropValue++;
MyService.SetMyProp(NewPropValue);
};
$scope.$watch(MyService.GetMyProp, function (newValue) {
alert("NewValue from Watch = " + newValue);
});
}).service('MyService', function () {
var myProp;
this.GetMyProp = function () {
return MyProp;
};
this.SetMyProp = function (newProp) {
MyProp = newProp;
};
});
function OutsideAngularChange() {
alert("OutsideAngularChange called")
angular.element(document.getElementById('CtrlHost')).scope().ChangeIt();
}
http://jsfiddle.net/jonnyknowsbest/4umxanpu/
Hit the "Change Inside Angular" button and the scope watch is triggered. Hit the "Change Outside Angular" button and the scope watch is NOT triggered.
Both buttons call the same scope method to update a service property.
How come one works and one does not?