Angular.js: Unknown provider: $rootElementProvider <- $rootElement <- $location

Created on 7 Apr 2014  路  4Comments  路  Source: angular/angular.js

Hi All,

I am not sure if this is an issue or not. When I run this code:

var myModule = angular.module('TestModule', []);
var injector = angular.injector(['TestModule', 'ng']);
var location = injector.get('$location');

I get the following exception

Uncaught Error: [$injector:unpr] Unknown provider: $rootElementProvider <- $rootElement <- $location

This seems to happen for all version in 1.2.

Regards,
Alex

Most helpful comment

@caitp thanks for your idea.

However, at the end, what is jqLite and how to get the injector for an already created module?

[EDIT] if your ng-app is on the body element you can do:

 angular.element(document.body).injector();

All 4 comments

ngMock will mock $rootElement for you for each spec, but otherwise you need to call angular.bootstrap to create an injector with a rootElement (or alternatively $provide.value('$rootElement', someDOMNode); in a config block)

This happens when I run this in the console for a running angular app. There should be a root element there.

No, you're creating a whole new injector there, no root element. angular.injector() is different from jqLite.injector() --- jqLite.injector() will act as a getter, while angular.injector() is the exported createInjector() function in src/AUTO/injector.js.

@caitp thanks for your idea.

However, at the end, what is jqLite and how to get the injector for an already created module?

[EDIT] if your ng-app is on the body element you can do:

 angular.element(document.body).injector();
Was this page helpful?
0 / 5 - 0 ratings