javascript - Angular 中的 $document 和 $window.document 有什么区别?

标签 javascript angularjs canvas

我在JSBin中试了下面的代码,第一个可以拿到canvas对象。但是,第二个不能。

JSBin:http://jsbin.com/natavejasa/1/edit?html,js,output

var canvas = $window.document.getElementById('myCanvas');

JSBin:http://jsbin.com/yareb/1/edit?html,js,output

var canvas = $document.getElementById('myCanvas');

所以我想知道 $window.document$document 之间有什么区别。

最佳答案

$document 等同于 angular.element(window.document) - window.document 的 jqLit​​e 包装器。

$window.documentwindow.document 相同 - 即它是 DOM 元素 document

以下是正确的:

$window.document === $document[0]

关于javascript - Angular 中的 $document 和 $window.document 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28120736/

相关文章:

javascript - 在div中显示文本而不重新加载页面

javascript - 无法读取 null 的属性 'insertBefore' - handsontable.full.js :3714

javascript - 在 Fabric.js 中剪切区域并设置 Canvas 背景

javascript - 从 UICalendar 中选择一天

c# - 在 WPF 中绘制数千个矩形

javafx - 从 JavaFX Canvas 中删除抗锯齿形状

javascript - 将数据刻度为分钟/小时 OHLC Javascript

javascript - Mocha + Babel + React 模块

javascript - 未调用 Angular 登录/注销功能

javascript - 更换时 Angular 模型不更新