I have a simple angularjs application with a single router at the moment :
angular.module('myApp', ['ngRoute'])
.config(['$routeProvider', function($routeProvider) {
$routeProvider.when('/editFilter/:id', {templateUrl: '/webapp/template/filterDetail'});
}])
My goal is to call the editFilter template when I need it. I am trying to retrieve the $location like that :
angular.injector(['myApp']).get('$location')
but it fails with
Error: [$injector:unpr] http://errors.angularjs.org/1.2.1/$injector/unpr?p0=%24rootElementProvider%20%3C-%20%24rootElement%20%3C-%20%24location%20%3C-%20%24route
If I call angular.injector(['myApp']).get('$location')
it returns true.
Any idea of what I am doing wrong? I have try several workaround but everytime I end up with a very similar error.
If you would have read the error page you see that you forgot to include certain dependencies. Please don't forget to include them. The one failing now is $rootElement, as you can read in the error. Include this one, and try again to see if other dependencies should be included.
EDIT: OK, I was wrong, after some reading I noticed that this method:
angular.injector(['myApp']).get('$location')
creates a new injector instance. This is not what you want I think. So I don't know what is your case but if you are in AngularJS just inject the $injector instance. If not in AngularJS call
$injector = angular.element([DOM element]).injector(); $injector.get('$location');
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