angularJS:相当于 $location.search 的 ui-router [英] angularJS: ui-router equivalent to $location.search
问题描述
我正在使用以下内容在我的数据网格中进行分页:
I'm using the following to do paging in my datagrid:
$location.search('page', page);
其中 page 是当前页码.
where page is the current page number.
然后我监听以下事件:
$scope.$on('$routeUpdate', function(next, current) {
$scope.currentPage = $routeParams.page ? Number($routeParams.page) : 1;
$scope.search();
});
在更新 URL 中的 currentPage 后,这会触发对我范围内的 search() 方法的调用.
That triggers a call to a search() method on my scope after updating the currentPage that is in the URL.
我如何将其转换为带有 ui-router 的状态?$routeUpdate 不再触发,因为我使用的是状态管理器而不是路由.
How would I translate that to states with ui-router ? The $routeUpdate is no longer triggered since I'm using a state manager instead of routes.
我的路线现在在状态提供者中定义如下:
My route is now defined in the state provider as such:
$stateProvider
.state('mandats', {
url: '/domiciliations/mandats',
templateUrl: 'domiciliations/views/mandats.html',
controller: 'mandatsCtrl'
})
推荐答案
我最终改为监听 $locationChangeSuccess 事件并解决了它.
I ended up listening to the $locationChangeSuccess event instead and that solved it.
这篇关于angularJS:相当于 $location.search 的 ui-router的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!