7

I have problem with adding Angulartics.

In my app.js I just added that two dependencies (Angulartics and the last one) you can see:

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 that 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 it goes well! Please help me :) thanks

I'm following this tutorial.

gion_13
  • 41,171
  • 10
  • 96
  • 108
Baierjak
  • 71
  • 2
  • maybe you should raise an issue at the angulartics github page – Alp May 29 '14 at 01:35
  • I haven't tried Angulartics, but I've had good luck with Angularytics, which likely does the same thing. [Angularytics](https://github.com/mgonto/angularytics) – Garrett McCullough May 29 '14 at 18:50

2 Answers2

4

Assuming you're reading 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'

1

Why are you using injector?

If you're using injector, you're not using the regular AngularJS bootstrapping code, so $rootElement is not defined.

You could mock the object:

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

Or define it in your app explicitely

smsApp.config(['$provide', function($provide) {
    // Should match the element that contains your ng-app="smsApp" attribute
    $provide.value('$rootElement', angular.element(document.body)); 
}]);
Blaise
  • 13,139
  • 9
  • 69
  • 97