如何在不使用location.reload()的情况下重新加载我的角度页面?

时间:2013-08-15 20:58:51

标签: angularjs coffeescript

这个问题似乎有两个答案:

    $scope.cancel = ->
      location.reload()

或:

    $scope.cancel = ->
      $route.reload()

第一个工作正常,但它是一个完整的GET,似乎做了比需要更多的工作。第二个似乎根本不起作用 - 我可以看到它遇到重载方法并用updateRoute排队this.$$asyncQueue.push(expr)函数,但重新加载不会发生。我可以强迫$route.reload工作吗?有没有更好的方法来实现这一目标?

Related SO post, but answer doesn't work.

1 个答案:

答案 0 :(得分:2)

你试过$ location.path(..)吗? angular $location service

 # this code handles the funky url that gets generated and keeps 
 #    the funk to a minimum
 # moment is a js library for dealing with time
 # typical url looks like: 
 # http://192.168.101.111:3001/#/admin/user/edit/M6E8WANLIAF%231376602267119
 # moment tag is after %23 and angular seems to deal with it just fine
    $scope.cancel = ->
      if (/#/.test($location.$$path))
        $location.path($location.$$path.replace(/#.*/, "##{moment()}"))
      else
        $location.path($location.$$path += "#" + moment());