3

I am having a hard time trying to figure out what is happening with routing in MVC and Angularjs. I am seeing different behavior between the 1.0.x version of Angularjs and the 1.3.x version.

I am building an MVC site with multiple "mini spas". I have an MVC controller called Registration and the route to it is http://mysite/Registration. The index view for that controller then renders a page containing the html and angular scripts.

I want to have angular routes that will render html templates and have set up the routing as follows.

// this works in 1.0.x
var registrationModule = angular.module("registrationModule", []);

registrationModule.config(function ($routeProvider, $locationProvider) {
        $routeProvider.when('/Registration/Members', { 
            templateUrl: '/templates/members.html', 
            controller: 'MembersController' });
        $routeProvider.when('/Registration/Updates', { 
            templateUrl: '/templates/updates.html', 
            controller: 'UpdatesController' });
    $locationProvider.html5Mode(true);
});

When I have the above routing and reference angularjs 1.0.x everything work as I would expect. The views load correctly and it does not post back to the server for the /Registration/* routes.

However, when I reference angular 1.3.x and have the following routing:

// this does not work in 1.3.x
var registrationModule = angular.module("registrationModule", ['ngRoute']);

registrationModule.config(function ($routeProvider, $locationProvider) {
        $routeProvider.when('/Registration/Members', { 
            templateUrl: '/templates/members.html', 
            controller: 'MembersController' });
        $routeProvider.when('/Registration/Updates', { 
            templateUrl: '/templates/updates.html', 
            controller: 'UpdatesController' });
    $locationProvider.html5Mode(true);
});

The views do not load on the /Registration/* routes and it posts back to the server for the RegistrationController to handle all /Registration/* routes.

Is there some fundamental difference in routing between the versions? Have I failed to implement angular routing correctly in the new version?

2
  • Have you referenced the additional JS file for the routing module? Also, do you see any errors being output in the console in the browser? Commented Mar 15, 2015 at 10:21
  • @mojo722 did you find an answer for this? Commented Aug 5, 2015 at 23:28

0

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.