Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between $window and window in Ionicframework

What is the exact difference between $window and window in ionic-framework?

For example, in the localstorage tutorial at learn.ionicframework.com/formulas/localstorage/ both $window and window are used.

like image 927
Riemann Avatar asked Mar 06 '15 19:03

Riemann


1 Answers

$window is an Angular service wrapping the global variable window, mainly to make it possible to mock it for unit tests:

A reference to the browser's window object. While window is globally available in JavaScript, it causes testability problems, because it is a global variable. In angular we always refer to it through the $window service, so it may be overridden, removed or mocked for testing.

If you look at the source, you'll see that there is not much more behind it:

function $WindowProvider() {
  this.$get = valueFn(window);
}
like image 147
Reto Avatar answered Oct 27 '22 05:10

Reto