Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between $document and $window.document in Angular?

I tried the following code in JSBin, the first one could get the canvas object. However, the second one cannot.

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

So I'm wondering what's the difference between $window.document and $document.

like image 780
LASkuma Avatar asked Jan 24 '15 00:01

LASkuma


1 Answers

$document is equivalent to angular.element(window.document) - a jqLite wrapper for window.document.

$window.document is the same as window.document - i.e. it is the DOM element document.

The following is true:

$window.document === $document[0]
like image 117
New Dev Avatar answered Oct 29 '22 06:10

New Dev