Daksh Khot
Daksh Khot

Reputation: 59

Error in using 'angular-route' or ever 'angular-ui-router'

I am using 'angular-route' for routing, but when I pass the 'ngRoute' module in dependent modules list i am getting an

Error:- Uncaught Error: [$injector:modulerr] http://errors.angularjs.org/1.3.15/$injector/modulerr?p0=MyApp&p1=Error%3A%…127.0.0.1%3A52621%2Fbower_components%2Fangular%2Fangular.min.js%3A38%3A135) in angular.js:38

Same is error arriving while using 'angular-ui-router'. I have properly passed the dependent module entry in modules list . Example:-

My app.js

1) when using 'angular-route'

define(['angular'], function(angular){
    return angular.module('MyApp',['ui.router']).
config(function($stateProvider,$urlRouterProvider) {
        $urlRouterProvider.otherwise("/");
        $stateProvider
         .state('Home', {
            url: "/",
            templateUrl: "views/home.html",
            controller: 'MyController'
         })
         .state('List',{
            url : "/list",
            templateUrl : "views/list.html",
            controller: 'MyController'
         })
    }); 
});

2) when using 'angular-ui-router'

    define(['angular'], function(angular){
     return angular.module('MyApp',['ngRoute']).
      config(function($routeProvider) {
        $routeProvider    
        .when('/',
            {
                controller: 'MYController',
                templateUrl: '/views/home.html'
            })
        .when('/list',
            {
                controller: 'MyController',
                templateUrl: '/views/list.html'
            })
        .otherwise({
            redirectTo: '/'
            });
        }); 
    });

I am not able to make out why is this error arriving, please help.

Upvotes: 2

Views: 293

Answers (1)

Aakash
Aakash

Reputation: 675

You should define external module in the define function , like you did not define ui-router as well as ngroute in the define function of requirejs ..

Try doing :

define(['angular','uiRouter'], function(angular){
return angular.module('MyApp',['ui.router']).

Upvotes: 1

Related Questions