Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Differences between document vs $document in Angular

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?

like image 960
JDo Avatar asked Oct 27 '15 08:10

JDo


1 Answers

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.

like image 68
Stefan Avatar answered Sep 25 '22 13:09

Stefan