Accessing $location from injector

Viewed 2100

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.

1 Answers
Related