AngularJS寻呼与$ location.path但没有ngView重装 [英] AngularJS Paging with $location.path but no ngView reload

查看:138
本文介绍了AngularJS寻呼与$ location.path但没有ngView重装的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的单页应用程序加载主页,我想展示的一系列理念。的想法每个显示在一个Flash动画的容器,与观念之间显示的循环动画。

My single page application loads a home page and I want to display a series of ideas. Each of the ideas is displayed in an animated flash container, with animations displayed to cycle between the ideas.

理念正在使用的$ HTTP加载:

Ideas are loaded using $http:

$scope.flash = new FlashInterface scope:$scope,location:$location

$http.get("/competition.json")
  .success (data) ->
    $scope.flash._init data

不过,从历史导航和UX利于我希望更新的地址栏使用$位置来显示每个想法正确的网址:

However, to benefit from history navigation and UX I wish to update the address bar to display the correct url for each idea using $location:

$location.path "/i/#{idea.code}"
$scope.$apply()

我打电话,因为$此事件来自outwith的AngularJS背景即闪存适用于此。我想对于电流控制器/视图保持和视图不重装。这是非常糟糕的,因为重装整个flash对象视图结果被抛弃和preloader周期重新开始。

I am calling $apply here because this event comes from outwith the AngularJS context ie Flash. I would like for the current controller/view to remain and for the view to not reload. This is very bad because reloading the view results in the whole flash object being thrown away and the preloader cycle beginning again.

我试过监听$ routeChangeStart做了preventDefault:

I've tried listening for $routeChangeStart to do a preventDefault:

$scope.$on "$routeChangeStart", (ev,next,current) ->
  ev.preventDefault()
$scope.$on "$routeChangeSuccess", (ev,current) ->
  ev.preventDefault()

但无济于事。整个事情是虎背熊腰,脚蹬dory没问题,如果我能想出​​重写视图重装时,我改变$ location.path的一种方式。

but to no avail. The whole thing would be hunky dory if I could figure out a way of overriding the view reload when I change the $location.path.

我还是很感慨我的办法解决AngularJS所以我很高兴在如何构建应用程序来实现我的目标的指针!

I'm still very much feeling my way around AngularJS so I'd be glad of any pointers on how to structure the app to achieve my goal!

推荐答案

而不是更新的路径,只更新页号查询参数。

Instead of updating the path, just update query param with a page number.

设置你的路线,忽略查询参数的变化:

set your route to ignore query param changes:

....
$routeProvider.when('/foo', {..., reloadOnSearch: false})
....

和在你的应用程序的更新 $位置

and in your app update $location with:

...
$location.search('page', pageNumber);
...

这篇关于AngularJS寻呼与$ location.path但没有ngView重装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆