How to redirect to another page using AngularJS?

前端 未结 12 671
深忆病人
深忆病人 2020-11-27 11:04

I am using ajax call to perform functionality in a service file and if the response is successful, I want to redirect the page to another url. Currently, I am doing this by

12条回答
  •  误落风尘
    2020-11-27 11:46

    You can redirect to a new URL in different ways.

    1. You can use $window which will also refresh the page
    2. You can "stay inside" the single page app and use $location in which case you can choose between $location.path(YOUR_URL); or $location.url(YOUR_URL);. So the basic difference between the 2 methods is that $location.url() also affects get parameters whilst $location.path() does not.

    I would recommend reading the docs on $location and $window so you get a better grasp on the differences between them.

提交回复
热议问题