Reputation: 135
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.
Upvotes: 12
Views: 9494
Reputation: 3141
$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);
}
Upvotes: 18
Reputation: 1136
Both are not related to ionic-framework as such.
window is a browser object which represents the window containing the DOM. 'document' that we use for javascript is a property of window object window.document.
refer this browser window object
where $window is a service created in angular which can be injected to any service or controller written in angular again to make use of its APIs.
refer to this for $window
Upvotes: 0