0

I have the following app in index.js:

angular.module('myApp', ['ngRoute', 'ngAnimate']);

    .config(function($urlRouterProvider, $locationProvider, $routeProvider) {

        $urlRouterProvider.otherwise('/');
        $locationProvider.html5Mode(true);
    });

And I have 2 routes /about and /contact, each route has his own file with controller (contact.controller.js) and contact.js where I configure the route like:

angular.module('myApp')

    .config(['$routeProvider',

        function($routeProvider) {

            $routeProvider.when('/about', {
                templateUrl: 'assets/javascript/about/about.html',
                controller: 'AboutCtrl',
                controllerAs: 'vm'
            });
        }
    ]);

My issue is if I do like this I recive this error

Uncaught Error: [$injector:nomod] http

But works I remove .config() from index.js.

What I'm doing wrong, can someone explain me how can I keep both configs?

Hiero
  • 2,182
  • 7
  • 28
  • 47

2 Answers2

2

To use $urlRouterProvider you need ui-router, but you are using angular router instead. Try like this:

$routeProvider.otherwise({ redirectTo: '/' });

I personally prefer ui-router

karaxuna
  • 26,752
  • 13
  • 82
  • 117
  • now works, but if I go to /blog for example, even if I have route created its 404\ – Hiero Feb 24 '16 at 12:00
  • @Hiero see this [question](http://stackoverflow.com/questions/13832529/how-to-config-routeprovider-and-locationprovider-in-angularjs) – karaxuna Feb 24 '16 at 12:03
1

You should Not have two configs in index.js what you can do is to append the code in single .config , So your code now becomes

angular.module('myApp', ['ngRoute', 'ngAnimate']);
.config(function($urlRouterProvider, $locationProvider, $routeProvider) {


// Rest of configurations.



function($routeProvider) {

        $routeProvider.when('/about', {
            templateUrl: 'assets/javascript/about/about.html',
            controller: 'AboutCtrl',
            controllerAs: 'vm'
        });
    }
]);

what i had in one of my projects was a long config function , so for the configurations and routes i have a single file index.js

Arnav Yagnik
  • 782
  • 1
  • 4
  • 14