2

In Angular, how do I redirect to a different page? With all the examples I've found, it only redirects to a relative URL, i.e. my currentURL+'#/new_newPath'.

Here is my code:

function mainController($scope, $http, $location) {

    // when submitting the add form, send the text to the node API
    $scope.createProperty = function() {
        $http.post('/api/property', $scope.formData)
            .success(function(data){
                $location.path( '/profile' );
            })
            .error(function(data){
            });
    };
}

I am originally at localhost/new_prop and i want to go to localhost/profile. Also, my angular app is located at localhost/new_property. if i go to localhost, i am not accessing my angular app. localhost/profile is also not part of the angular app

This seems like it should be really straightforward....

2 Answers 2

2

I think you can do

$window.location.href = '/profile';

Since $window will cause the reloading of the page.

The official documentation says about $location:

It does not cause a full page reload when the browser URL is changed. To reload the page after changing the URL, use the lower-level API, $window.location.href.

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

Comments

1

You want to use $window not $location.

$window contains location.href try setting that.

$window.location.href = '/profile';

You can refer to this post: Redirect to new Page in AngularJS using $location for more info.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.