Following angular.ui
Modal example receives three parameters. while $scope is the injected variable, how are we getting the other two $modal
and $log
. If they are injected automatically, how can one learn about all possible injected parameters?
angular.module('ui.bootstrap.demo')
.controller('ModalDemoCtrl',
function ($scope, $modal, $log) {
Thanks!
Angular's documentation for its dependency injection is pretty good
Essentially Angular will actually look at the function definition to do injection. It's not that $scope
is injected first, it's that $scope
is injected because you are using the name $scope
and that service exists. Same with the other two.
You can inject any service available to the module. Services that ship with Angular itself (always available) are listed here, but you can define your own services and include other modules that define services too.
There are other methods of dependency injection that provide a bit more clarity:
("symbol", ["$scope", function (anotherName) {
In the above example, anotherName
is actually the $scope
service in the context of that function (although I recommend not changing service names).
They are indeed injected automatically. Over here you can find more information about how this actually works and see some of the parameters typically available for injection. Since you can make your own services, directives etc, I think it's unlikely you'll find an exhaustive list anywhere.
In fact, the $modal parameter for example isn't something magical in angular, but in fact a service that the angular ui team happened to write.