hakuna
hakuna

Reputation: 6701

AngularJs - changing from ngRoute to ui-router throwing Error: [$injector:unpr]

I changed the routing in my app from ngRoute to ui-router,i am getting two errors:

  1. SyntaxError: Unexpected string
  2. Uncaught Error: [$injector:unpr]

config.route.js:

(function () {
  var app = angular.module('app');

  //Collect the routes
  app.constant('routes', getRoutes());    

  app.config(['$stateProvider', '$urlRouterProvider', 'routes', routeConfigurator]);
  function routeConfigurator('$stateProvider', '$urlRouterProvider', routes) {
    routes.forEach(function (r) {
      $stateProvider.state(r.url, r.config);
    });
    $urlRouterProvider.otherwise('/');
  }

  //Define the routes
  function getRoutes() {
    return [
      {
        url: '/',
        config: {
          templateUrl: 'app/components/dashboard/test/dashboard.html',
          title: 'dashboard',
          settings: {
            nav: 1,
            content: '<i class="fa fa-dashboard"></i> Dashboard'
          }
        }
      }, {
        url: '/admin',
        config: {
          title: 'admin',
          templateUrl: 'app/components/admin/admin.html',
          settings: {
            nav: 2,
            content: '<i class="fa fa-lock"></i> Admin'
          }
        }
      }
    ];
  }
})();

Previously it was as follows and working fine:

app.config(['$routeProvider', 'routes', routeConfigurator]);
  function routeConfigurator($routeProvider, routes) {
    routes.forEach(function (r) {
      $routeProvider.when(r.url, r.config);
    });
    $routeProvider.otherwise({ redirectTo: '/' });
  }

The ui-router module is referenced correctly in app.js, angular-ui-router.min.js file is loading successfully on index.html loading. What am i doing wrong ? Please help !

Upvotes: 0

Views: 412

Answers (1)

Michel
Michel

Reputation: 28339

function routeConfigurator('$stateProvider', '$urlRouterProvider', routes)

should be

function routeConfigurator($stateProvider, $urlRouterProvider, routes)

That is why you get a Unexpected string error.

The second error is a consequence of the first.

Upvotes: 1

Related Questions