From 13a889d38d2c948383e39b2afe0cadbf6c355156 Mon Sep 17 00:00:00 2001 From: Adam Coldrick Date: Tue, 21 Feb 2017 22:33:25 +0000 Subject: [PATCH] Fix search controller reloading when a text parameter is added This replaces the use of $stateParams with parsing the query string in the given URL instead, using $location. This way the controller doesn't reload when a text parameter is added to the URL, which was causing non-text criteria to be lost upon the addition of a text criterion. Change-Id: If1fbf8ce4a06538c97aa430cf5c8e703ac453db0 Task: 3493 --- src/app/search/controller/search_controller.js | 7 ++++--- src/app/search/module.js | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/app/search/controller/search_controller.js b/src/app/search/controller/search_controller.js index 81e15f9b..796f4a1b 100644 --- a/src/app/search/controller/search_controller.js +++ b/src/app/search/controller/search_controller.js @@ -18,7 +18,7 @@ * This controller provides initialization logic for the generic search view. */ angular.module('sb.search').controller('SearchController', - function ($log, $q, $scope, Criteria, $stateParams) { + function ($log, $q, $scope, Criteria, $location) { 'use strict'; /** @@ -39,9 +39,10 @@ angular.module('sb.search').controller('SearchController', /** * If a 'q' exists in the state params, go ahead and add it. */ - if ($stateParams.hasOwnProperty('q') && !!$stateParams.q) { + var params = $location.search(); + if (params.hasOwnProperty('q') && !!params.q) { $scope.defaultCriteria.push( - Criteria.create('Text', $stateParams.q) + Criteria.create('Text', params.q) ); } } diff --git a/src/app/search/module.js b/src/app/search/module.js index 411fbb46..08f12c59 100644 --- a/src/app/search/module.js +++ b/src/app/search/module.js @@ -26,7 +26,7 @@ angular.module('sb.search', // Set our page routes. $stateProvider .state('sb.search', { - url: '/search?q', + url: '/search', templateUrl: 'app/search/template/index.html', controller: 'SearchController' });