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?
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