How can I parse the below URL query string to get the value of the quantity parameter?
myurl/Channels/BuyCredits?quantity=2
I have tried numerous examples without success:
I just tried this example:
marvmentApp.controller("channelCreditController", function($scope, $http, $compile, $location) {
var params, test2;
$scope.parseQueryString = function() {
var objURL, str;
str = window.location.search;
objURL = {};
str.replace(new RegExp("([^?=&]+)(=([^&]*))?", "g"), function($0, $1, $2, $3) {});
objURL[$1] = $3;
return;
return objURL;
};
params = $scope.parseQueryString();
test2 = params['quantity'];
debugger;
});
I keep getting an error $1 is udefined
$0 - $3only exist within the scope of your empty functionfunction($0, $1, $2, $3) {}. (And there are much easier ways to extract a query param.)