0

I am trying to change the URL of the page if an $html callback is a success.

Module:

var app = angular.module('mymodule', ['ngRoute','ui.bootstrap']);

app.config(function($locationProvider, $routeProvider) {
$locationProvider.html5Mode(true);

$routeProvider.
    when('/Home/Index', {
        templateUrl: '/Home/Index',
        controller: 'HomeController'
    });
});

Controller:

$http({
        method: 'POST',
        url: '/User/InsertInitialUserInfo',
        data: insertUserParams
    }).success(function (data, status) {
        $location.url("/Home/Index");
    }).error(function (data, status) {
        console.log(status);
    });

MVC Controller

    public ActionResult Index()
    {
        return View();
    }

After my controller code runs the URL changes from : localhost:xxxx/Home/Register to localhost:xxxx/Home/Index

But the view doesn't change. What am I missing?

4
  • did you try using $location.path("/Home/Index") Commented Jul 6, 2014 at 1:23
  • 1
    Try $location.url("Home/Index"); And you have of course an ng-view declaration in your view. Commented Jul 6, 2014 at 7:18
  • $location.path didn't work too. @Edminsson, you got it. I was missing ng-view declaration. Commented Jul 6, 2014 at 8:43
  • Could you post it as an answer please? Commented Jul 6, 2014 at 8:44

1 Answer 1

1

You are only missing one important component, the ng-view declaration in your view

<div ng-view></div>

This is placeholder for the templates you specify in the app.config.

Sign up to request clarification or add additional context in comments.

Comments

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.