Angularjs Referenceerror: $locationProvider is not defined

Asked

Viewed 76 times

0

I’m making the mistake of

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' })

}]);
  • I changed the config and gave no more error however the routes do not work. . config(Function ($stateProvider, $urlRouterProvider, $locationProvider)

1 answer

0

In Angularjs you need to inject the dependencies in the order you will receive as a function parameter.

The array that the function ". config()" is set as a parameter:

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

2 - The last parameter of the array obligatorily must be a function, which will have the dependency items specified previously in the array injected into the parameters of this function, obeying 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 error, use below:

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' });
}]);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.