Use $window instead of global window

While window is globally available in JavaScript, it causes testability problems, because it is a global variable. Using the $window service it may be overridden, removed or mocked for testing.