0

What exactly does the "inject" line do?:

function PhotoGalleryCtrl($route, $xhr) {
}

PhotoGalleryCtrl.$inject = ['$route', '$xhr'];

Are $route and $xhr predefined somewhere? Where to read about them?

Who said that the PhotoGalleryCtrl function has the .$inject method?

1 Answer 1

2

Both $route and $xhr are native AngularJS services, the latter has been replaced by $http in the most recent versions of AngularJS. They are part of the ng module.

You can read about them here

$inject tells angular to make available those services to the controller PhotoGalleryCtrl

Dependency injection and modules are core features of Angular. They both minimize global state and allow for better unit testing, you can read more about them here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.