I have a URL like that:
http://myproject.com/apartments?location=123&arrival=01&departure=456&rooms=789
How can I get the value of location, arrival, departure, rooms and pass it to my service.
I try to using $location.search() but I can not get the values. The result:
Object { location=undefined, arrival=undefined, departure=undefined, more...}
My serivce:
angular.module('apartmentService', [])
.factory('Apartment', function ($http) {
return {
get: function (parameters) {
console.log(parameters);
return $http({
method: 'GET',
url: '/api/apartments',
params: {location: parameters}
});
}
};
});
My controller:
angular.module('apartmentCtrl', [])
.controller('ApartmentController', function ($scope, $http, $location, Apartment) {
$scope.loading = true;
$scope.parameters = {
location: $location.search().location,
arrival: $location.search().arrival,
departure: $location.search().departure,
rooms: $location.search().rooms
};
Apartment.get($scope.parameters).success(function (data) {
$scope.apartments = data;
$scope.loading = false;
});
});
string.split(),string.indexOf()should be enough, no?