The link to my SPA is constructed of an absolute URL + Query-String parameter as the following:
http://127.0.0.1/Pepole/Index?personId=[some_ID]
And my route configuration is:
tmc.config(['$routeProvider', function ($routeProvider) {
$routeProvider.when('/', { templateUrl: '/People/Person', controller: peopleController });
$routeProvider.otherwise({ redirectTo: '/' });
}]);
Given my config, when routing to /, how can I retain the personId parameter so it would be available in the respective controller (peopleController) and I will be able to access it.
http://docs.angularjs.org/api/ng.$location#search
search(search, paramValue)
This method is getter / setter.
Return search part (as object) of current url when called without any parameter.
Change search part when called with parameter and return
$location.Parameters
search(optional)–{string|object<string,string>=}– New search params - string or hash object
paramValue(optional)–{string=}– Ifsearchis a string, thenparamValuewill override only a single search parameter. If the value isnull, the parameter will be deleted.
Returns
{string} – search
function SomeCtrl($scope, $location) {
$scope.personId = $location.search().personId;
}
Inject $routeParams in your controller and then simply call $routeParams.yourQueryParameter.
For example:
function SomeCtrl($scope, $routeParams) {
$scope.personId = $routeParams.personId;
}