2

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.

1 Answer 1

1

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']).
Sign up to request clarification or add additional context in comments.

2 Comments

After doing what you said i.e. adding the external module "uiRouter" in define function I am getting an error:- Uncaught Error: Invalid require call requirejs.org/docs/errors.html#requireargs and previous error is coming as it is :- Uncaught Error: [$injector:modulerr] errors.angularjs.org/1.3.15/$injector/……127.0.0.1%3A55852%2Fbower_components%2Fangular%2Fangular.min.js%3A17%3A381) My main.js where i have used require.config to load all js and export modules is :- pastie.org/10198002
I think you should define a baseurl in your require.config require.config( baseUrl: '<your current directory>' paths : { 'angular' : '../bower_components/angular/angular.min', The 'paths:{}' , will be evaluated relative to the baseUrl ... Your angular error also points that your app is not able to find angular.js file , and the path to angular.js is defined in your require.config only ..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.