AngularJs ReferenceError: $ locationProvider is not defined

0

I'm in error with

  

ReferenceError: $ locationProvider is not defined.

I'm using angular-ui-router. Can you help me?

obs: I removed the #.

    var app = angular.module("app", ['ui.router', 'angularUtils.directives.dirPagination']);

app.config([$locationProvider, function ($stateProvider, $urlRouterProvider) {

    $locationProvider.html5Mode(true);

    $urlRouterProvider.when("", "/Index");

    $stateProvider
    .state('/Empresas', 
            { templateUrl: $("#linkBase").attr("href") + 'templates/Empresa/empresas.html', 
                 controller: 'EmpresaController' })
    .state('/Usuarios', 
            { templateUrl: $("#linkBase").attr("href") + 'templates/Usuario/usuarios.html', 
                controller: 'UsuarioController' })

}]);
    
asked by anonymous 29.03.2018 / 15:09

1 answer

0

In AngularJS you need to inject the dependencies in the order you are going to receive as a function parameter.

The array that the ".config ()" function receives as a parameter should look like this:

1 - List of names in string format with the registered name of the object (provider, constants, etc) separated by commas.

2 - The last parameter of the array must be a function, which will have the dependency items previously specified in the array injected in the parameters of this function, in the same order. The names of the parameters in the function can be defined as best understood, but it is customary to use the same name that was registered.

To correct your mistake, use the following:

var app = angular.module("app", ['ui.router', 'angularUtils.directives.dirPagination']);

app.config(['$stateProvider', '$locationProvider', '$urlRouterProvider' 
   function ($stateProvider, $locationProvider, $urlRouterProvider) {

    $locationProvider.html5Mode(true);
    $urlRouterProvider.when("", "/Index");
    $stateProvider('/Empresas', 
        { templateUrl: $("#linkBase").attr("href") + 'templates/Empresa/empresas.html', 
             controller: 'EmpresaController' })
.state('/Usuarios', 
        { templateUrl: $("#linkBase").attr("href") + 'templates/Usuario/usuarios.html', 
            controller: 'UsuarioController' });
}]);
    
03.04.2018 / 16:44