AngularJS reloadOnSearch不工作 [英] AngularJS reloadOnSearch not working

查看:205
本文介绍了AngularJS reloadOnSearch不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

执行搜索和导航离开我希望用户能够返回到搜索页面(通过点击回到浏览器),并保留当前的搜索参数后。我逐渐认识到,为了做到这一点,页面url必须进行更新,以包含有关页面数据。随着研究,我发现我可以用 $位置更新位置和强制页面不重新加载使用 reloadOnSearch 中的路由。然而,由于某些原因,当我改变搜索参数(网​​址是什么?... ),实际上的页面不重新加载。
任何想法如何修复它prevent重装?

After performing a search and navigating away i want the user to be able to return to the search page (by hitting back in the browser) and retain the current search parameters. I've come to realize that in order to do this, the pages url must be updated to contain data about the page. With research i found i can update the location using $location and force the page NOT to reload when a change is made by using reloadOnSearch in the routes. However, for some reason when i change the search parameters (url?...) the page in fact does reload. Any idea of how to fix it to prevent reloading?

routes.coffee:

'use strict'

angular.module('app.rc.routes', ['ui.router'])
  .config ['$stateProvider', '$urlRouterProvider', ($stateProvider, $urlRouterProvider) ->
    $urlRouterProvider.otherwise '/'
    $stateProvider
      ...
      .state('resource_center.search',
        url: '/resources/search?term'
        templateUrl: 'views/rc/search.html'
        controller: 'SearchCtrl'
        reloadOnSearch: false
      )
      ...
  ]

search.coffee:

'use strict'
angular.module('app.rc.controllers').controller 'SearchCtrl', ['$scope', '$state', '$http', '$stateParams', '$location', ($scope, $state, $http, $stateParams, $location) ->
  $scope.term = $stateParams.term || ''
  $scope.updateResults =  ->
    console.log "Loading Results"
    ...
    $location.search({term: $scope.term})

参考文献:

作为参考,如何正确地做到这一点,我使用:<一href=\"http://stackoverflow.com/a/12481175/1382588\">http://stackoverflow.com/a/12481175/1382588

As a reference to how to properly do this, I was using: http://stackoverflow.com/a/12481175/1382588

推荐答案

reloadOnSearch目前不UI路由器支持

reloadOnSearch isn't currently supported by ui-router

https://github.com/angular-ui/ui-router/问题/ 367

您应该能够做你想做的UI路由器做什么用有两种状态:一个搜索页面状态,以及搜索结果孩子的状态

You should be able to do what you want to do in ui-router by having two states: a search page state, and a search results child state.

搜索将在/搜索为例,在搜索/搜索/ {}查询结果。搜索页面将有一个视图来显示搜索框,并显示搜索结果的嵌套视图。搜索按钮将做一个状态变化到搜索结果的状态。该会导致搜索结果嵌套视图进行更新,在不改变搜索页面的外观。

search will be at /search for example, and search results at /search/{query}. The search page will have a view to display the search box, and a nested view to display the search results. The search button will do a state change to the search results state. The will cause the search results nested view to update, without changing the appearance of the search page.

这篇关于AngularJS reloadOnSearch不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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