I have a group of window variables that I want to bind to a scope variable in AngularJS.
Here's my code so far but it doesn't work:
.directive('watchGlobals', function() {
return {
link: function(scope, element, attrs) {
var watchGlobals = attrs.watchGlobals.split(',');
for (var i = 0; i < watchGlobals.length; i++) {
scope[watchGlobals[i]] = window[watchGlobals[i]];
}
}
}
});
What's the optimal way to do this? I'm trying to avoid having to use setInterval. I'd like to have the scopes updated whenever the window variable is updated. Is there a way I can watch window variables from within AngularJS like this?