redirect to an absolute url in angularjs

前端 未结 4 1296
不知归路
不知归路 2020-12-30 01:33

How to redirect user to an absolute url in angularjs.

For example: i have a page, my current url (http://example.com/submit), once the user click some button in th

相关标签:
4条回答
  • 2020-12-30 01:49

    You need to use the browser level API, with the object window, or you can inject the $window reference in your controller.

    • window.location.href="http://www.google.com";
    • $window.location.href="http://www.google.com";

    References:

    window

    $window

    Best solution should be perform redirect in your $routeProvider configuration, injecting the $window object and performing all redirection you need.

    0 讨论(0)
  • 2020-12-30 01:59

    I had some issues with the above solutions and came across this and thought I would share. Be sure to inject '$timeout', '$window' into your controller.

            $timeout(function() {
                 $window.location.assign('https://URL');
    
             }, 3000);
    
    0 讨论(0)
  • 2020-12-30 02:03

    What about simple window.location.href = "http://google.com"?

    0 讨论(0)
  • 2020-12-30 02:03

    you can use window.location.href="" and in between your quotes you can place your respective url

    0 讨论(0)
提交回复
热议问题