AngularJS, Internet Explorer 9 and watch error

While working on an enterprise project (of course…) I run into an error with Angular (1.3.13), Internet Explorer 9 and $watch-ing a scope when programming a directive:

 

TypeError: Object doesn’t support property or method ‘watch’

I’ll never find out what the reason is. The collective wisdom of Angular users claims that including JQuery solves it, for me it didn’t (neither did ES5 shim). I ended up working entirely around $watch by using application logic:


app.directive("footer", ["$rootScope", function($rootScope){
return {
restrict: 'E',
scope: {
user: '='
},
template: 'home | loginlogout {{activeUser.id}} | workspaces',
controller: function($scope) {
$scope.watch("user",function(){

//....

});
$scope.activeUser=app.user;
});
}
};
}]);

1. a setter which is notified of the change
2. custom jquery events which are fired by the setter
3. The directive listens to the jquery events

 

Resources

[1] ES5 Shim
https://github.com/es-shims/es5-shim

[2] JQuery events
http://learn.jquery.com/events/introduction-to-custom-events/

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.