Regarding $location.search, the docs say,
Return search part (as object) of current url when called without any parameter.
In my
My fix is more simple, create a factory, and implement as one variable. For example
angular.module('myApp', [])
// This a searchCustom factory. Copy the factory and implement in the controller
.factory("searchCustom", function($http,$log){
return {
valuesParams : function(params){
paramsResult = [];
params = params.replace('(', '').replace(')','').split("&");
for(x in params){
paramsKeyTmp = params[x].split("=");
// Si el parametro esta disponible anexamos al vector paramResult
if (paramsKeyTmp[1] !== '' && paramsKeyTmp[1] !== ' ' &&
paramsKeyTmp[1] !== null){
paramsResult.push(params[x]);
}
}
return paramsResult;
}
}
})
.controller("SearchController", function($scope, $http,$routeParams,$log,searchCustom){
$ctrl = this;
var valueParams = searchCustom.valuesParams($routeParams.value);
valueParams = valueParams.join('&');
$http({
method : "GET",
url: webservice+"q?"+valueParams
}).then( function successCallback(response){
data = response.data;
$scope.cantEncontrados = data.length;
$scope.dataSearch = data;
} , function errorCallback(response){
console.log(response.statusText);
})
})