AngularJS Error: [$ injector: unpr] Unknown provider:

2

I have the following error for dependency injection in my controller:

  

Error: [$ injector: unpr] Unknown provider: $ routeProviderProvider

asked by anonymous 19.09.2016 / 20:20

1 answer

2

A provider is only available in the configuration cycle:

var module = angular.module('MainModule', ['ui.filters', 'ngRoute']);

module.config(function($routeProvider) { // Ciclo de configuração
    $routeProvider.when("/", {
        templateUrl : "consult.htm"
    });
});

To use during the run cycle, use the service directly:

//Utilize $route, não $routeProvider
module.controller('MainCtrl', function($scope, $route) { 
    $scope.route = $route;
});
    
20.09.2016 / 01:29