Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Injector error using Angulartics with AngularJS

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.

like image 730
Baierjak Avatar asked May 14 '14 10:05

Baierjak


2 Answers

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'

like image 170
Bobby Duebelbeis Avatar answered Nov 17 '22 03:11

Bobby Duebelbeis


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)); 
}]);
like image 29
Blaise Avatar answered Nov 17 '22 03:11

Blaise