Home:ALL Converter>Differences between document vs $document in Angular

Differences between document vs $document in Angular

Ask Time:2015-10-27T16:31:23         Author:JDo

Json Formatter

What are the differences between using document and $document while developing Angular's applications? I read that it's better to use angular's equivalents like: $window instead of window or $timeout instead of setTimeout.

But... why? I thought window, setTimeout and document are faster because they are native and doesn't need to "pass through" code of Angular framework.

Is it better to use Angular's equivalents instead of native functions, objects from JS?

Author:JDo,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/33363054/differences-between-document-vs-document-in-angular
Stefan :

By using the angular services for $document and $window you make your code unit test ready.\nThis dependency injection allows you to use mock versions of $document or $window in your tests.\n\nThe performance impact mentioned can be ignored.",
2015-10-27T08:39:18
Furkan Başaran :

$document is a jQuery object, $(document).\n\nSo basically you should be able to do: \n\n$document[0].property = document.property\n\n\nYou can look at this for an example.",
2015-10-27T08:37:55
Atul Kumar :

Following is always true:\n$window.document === $document[0]",
2015-10-27T08:35:11
yy