Andre Aquiles
Andre Aquiles

Reputation: 404

ngMeta injection error

I'm trying to use ngMeta to share facebook posts with his proper meta attributes. However, I'm not receiving any kind of information. My ngMeta in the html is being ignored. I'm not being able to "run" the block.

Here is my code:

var vToken, myURL;
var site4R = angular.module('site4R', ['myServices', 'ngRoute', 'ui.bootstrap', '720kb.socialshare', 'ngRoute'])
.config(['$routeProvider', '$locationProvider','$qProvider', function($routeProvider, $locationProvider, $qProvider) {



  $qProvider.errorOnUnhandledRejections(false);
  $locationProvider.html5Mode(true);

  $routeProvider
  .when('/', {
    templateUrl: 'partials/home.html',
    controller: 'home',
    meta: {
      'title': 'Trolei',
      'description': 'Troslei'
    }
  })
  .when('/#tabc1', {
    templateUrl: 'partials/home.html#tabc1',
    controller: 'home',
    meta: {
      'title': '4R Sistemas - Tabc1',
      'description': '4R Sistemas & Assessoria LTDA'
    }
  })
  .when('/#tabc3', {
    templateUrl: 'partials/home.html#tabc3',
    controller: 'home',
    meta: {
      'title': '4R Sistemas - Tabc3',
      'description': '4R Sistemas & Assessoria LTDA'
    }
  })
  .otherwise({
    redirectTo: '/404',
    templateUrl: 'partials/404.html',
    controller: 'home'
  });

}])



.run(function($rootScope, $location, $route, $routeParams, $token, $dados, $window, ngMeta) {

   //Hidden unnecessary code
  
  ngMeta.init();
});
<meta property="og:title" content="{{ngMeta.title}}">
<meta name="description" content="{{ngMeta.description}}">

When I try to inject it, I get the followed error:

angular.min.js:42 Uncaught Error: [$injector:unpr] 
http://errors.angularjs.org/1.6.0/$injector/unpr?p0=ngMetaProvider%20%3C-
%20ngMeta
at angular.min.js:6(...)

I'm using Angular 1.6 with this SPA.

This code is not mine, and I'm not even a beginner with Angular, however, I may need to fix this. Could anyone give me a hand about what should I do?

PS: I deleted some unnecessay code, I can edit it if needed.

Upvotes: 0

Views: 187

Answers (1)

Pankaj Parkar
Pankaj Parkar

Reputation: 136174

Inject ngMeta module into your site4R app dependency array.

var site4R = angular.module('site4R', [
  'myServices', 
  'ngRoute', 
  'ui.bootstrap', 
  '720kb.socialshare', 
  'ngMeta' //<-- inject dependency before using it.
])

Upvotes: 1

Related Questions