AngularJS view doesn't change when navigating to link

后端 未结 2 1658
悲&欢浪女
悲&欢浪女 2021-01-02 20:11

I\'m baffled by the following: I have a simple link like this:

    
  • Foos
  • but when cli

    相关标签:
    2条回答
    • 2021-01-02 20:54

      I have been able to resolve this issue by adding target="_self" to the link.

      <li><a href="#/foo" target="_self">Foos</a></li>
      

      I found this resolution here.

      0 讨论(0)
    • 2021-01-02 21:16

      Ok, so apparently, this is a known issue of sorts: when the locationProvider (i.e. $location) is injected to one controller, links cease to work globally. One workaround seems to be to rewrite the links via jQuery, and that works:

      app.run(function($rootScope) {
          $('[ng-app]').on('click', 'a', function() {
              window.location.href = $(this).attr('href');
          });
      });
      
      0 讨论(0)
    提交回复
    热议问题