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.
$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);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With