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})
References:
As a reference to how to properly do this, I was using: https://stackoverflow.com/a/12481175/1382588