Injector error using Angulartics with AngularJS

I have a problem adding Angulartics .

In my app.js, I just added that two dependencies ( Angulartics and the latter):

var smsApp = angular.module('smsApp', [ 'ngRoute', 'smsControllers', 'smsFilters', 'google-maps', 'pascalprecht.translate', 'angulartics', 'angulartics.google.analytics', ]); 

and then in my index.html I added:

 <script src="./js/angulartics.js"> <script src="./js/angulartics-ga.js"> ---- paths to these files are ok 
but when I want to create this module with:
 var injector = angular.injector(['smsApp', 'ng']); 

I got this error:

Uncaught Error: [$injector:unpr] http://errors.angularjs.org/1.2.15/$injector/unpr?p0=%24rootElementProvider%20%3C-% 20% 24rootElement% 20% 3C-% 20% 24location

Without Angulartics, everything is going well! Please help me :) thanks

I follow this tutorial .

+7
javascript angularjs google-analytics angulartics
source share
2 answers

Assuming you read the docs here: https://github.com/angulartics/angulartics

You need to install the angularitics.google.analytics plugin by running "bower install angulartics-google-analytics --save"

+4
source share

Why are you using an injector?

If you use injector , you are not using regular AngularJS boot code, so $rootElement is undefined.

You can mock the object:

 <script src="/path/to/angular-mock.js"> ... var injector = angular.injector(['smsApp', 'ngMock', 'ng']); 

Or define it explicitly in your application

 smsApp.config(['$provide', function($provide) { // Should match the element that contains your ng-app="smsApp" attribute $provide.value('$rootElement', angular.element(document.body)); }]); 
+1
source share

All Articles