Am I doing the right thing here ?
Q. How do you update your Angular model from outside code ?
A. If you know the DOM element that contains your Angular model's scope you can call a controller method via $apply() which will refresh the view automatically :
// get Angular scope from the known DOM element
e = document.getElementById('myAngularApp');
scope = angular.element(e).scope();
// update the model with a wrap in $apply(fn) which will refresh the view for us
scope.$apply(function() {
scope.controllerMethod(val);
});
Example: This example shows how an interval timer can send repeated updates to the Model by getting the scope and then calling my controllers MainCtrl.setTicks() method from within scope.$apply()
![](https://lh5.googleusercontent.com/-8x8kBpLHczw/UBc4854iLJI/AAAAAAAAJIQ/1Fx28T5huSk/s200/angular-interop-test.png)
References :