Redirect using AngularJS

后端 未结 6 1316
情书的邮戳
情书的邮戳 2020-11-30 02:28

I\'m trying to redirect to another route using:

$location.path(\"/route\");

But for some reason it is not working. I did an auto-complete w

相关标签:
6条回答
  • 2020-11-30 02:34

    Assuming you're not using html5 routing, try $location.path("route"). This will redirect your browser to #/route which might be what you want.

    0 讨论(0)
  • 2020-11-30 02:34

    It is hard to say without knowing your code. My best guess is that the onchange event is not firing when you change your textbox value from JavaScript code.

    There are two ways for this to work; the first is to call onchange by yourself, and the second is to wait for the textbox to lose focus.

    Check this question; same issue, different framework.

    0 讨论(0)
  • 2020-11-30 02:40

    If you need to redirect out of your angular application use $window.location. That was my case; hopefully someone will find it useful.

    0 讨论(0)
  • 2020-11-30 02:44

    With an example of the not-working code, it will be easy to answer this question, but with this information the best that I can think is that you are calling the $location.path outside of the AngularJS digest.

    Try doing this on the directive scope.$apply(function() { $location.path("/route"); });

    0 讨论(0)
  • 2020-11-30 02:47

    Don't forget to inject $location into controller.

    0 讨论(0)
  • 2020-11-30 02:53

    Check your routing method:

    if your routing state is like this

     .state('app.register', {
        url: '/register',
        views: {
          'menuContent': {
            templateUrl: 'templates/register.html',
          }
        }
      }) 
    

    then you should use

    $location.path("/app/register");
    
    0 讨论(0)
提交回复
热议问题