我在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
的 jqLite 包装器。
$window.document
与 window.document
相同 - 即它是 DOM 元素 document
。
以下是正确的
:
$window.document === $document[0]
关于javascript - Angular 中的 $document 和 $window.document 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28120736/