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?
By using the angular services for $document and $window you make your code unit test ready. This dependency injection allows you to use mock versions of $document or $window in your tests.
The performance impact mentioned can be ignored.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With