I'm struggling with passing and reading multiple query string parameters in a route.
$routeProvider.when("/joboffers:keywords:location", {
controller: "jobOffersController",
templateUrl: "/App/Views/JobOffer/All.html"
});
This is the search page:
$scope.searchJobOffer = function () {
var vm = $scope.jobOfferSearchViewModel;
var path = "/joboffers?keywords=" +( vm.keywords || "") + "&location=" + (vm.location || "");
$location.path(path);
}
And this is the JobOffersController:
'use strict';
app.controller('jobOffersController', ['$scope', '$routeParams', 'jobOfferService', function ($scope, $routeParams, jobOfferService) {
$scope.jobOffers = [];
function init() {
var keywords = $routeParams.keywords;
var location = $routeParams.location;
}
init();
}]);
Reading the $routeParams is not working at all. If I pass "developer" as a keyword and "New York" as location, the $routeParam object looks like this:
{keywords: "?keywords=developer&location=New Yor", location: "k"}
Can somebody tell me what I'm doing wrong? Thanks in advance.
P.S.
Is it possible that this is because of a wrongly configured route?
When I navigate via the searchJobOffer
function, it encodes the URL to this: http://localhost:49380/#/joboffers%3Fkeywords=developer&location=london
and if I try to use this url http://localhost:49380/#/joboffers?keywords=developer&location=london
, the routing system drops me to the default route (#/home)
$routeParams
are only updated after a route change completes successfully. You sure this is the case? – Rotative