Ionicframework中$ window和window之间的区别 [英] Difference between $window and window in Ionicframework

查看:135
本文介绍了Ionicframework中$ window和window之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

离子框架中$ window和window之间的确切区别是什么?

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

例如,在learn.ionicframework.com/formulas/localstorage的localstorage教程中/ $窗口和窗口都被使用。

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

推荐答案

$ window 是一个包装全局变量窗口的Angular服务,主要是为了模拟它进行单元测试:

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


对浏览器窗口对象的引用。虽然窗口在JavaScript中是全局可用的,但它会导致可测试性问题,因为它是一个全局变量。在角度我们总是通过$ window服务引用它,因此它可能被覆盖,删除或模拟以进行测试。

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);
}

这篇关于Ionicframework中$ window和window之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆