Reputation: 700
So I am using ui-Router
in my app to pass $stateParams
and use them in my controllers in more or less clever ways. Point is, some of these $stateParams
that I pass contain sensitive information, like employee ids. Is there a way to hide them in the url? I saw some answers here about params, but I am not 100% sure that this was the problem those answers were addressing.
So just to be clear, I am talking about information passed in the url like this:
.state('detail', {
url: '/detail/:employeeid/:employeename/:employeeteam',
templateUrl: 'templates/EmployeeReport.html',
controller: 'ReportController'
})
I want to hide employeeid
, employeename
and employeeteam
.
Thanks!
Upvotes: 3
Views: 2415
Reputation: 1290
Yes. You can use params
.
Docs - here
So you can modify your state
as follows,
.state('detail', {
url: '/detail',
templateUrl: 'templates/EmployeeReport.html',
controller: 'ReportController',
params: {
employeeid: null, // can initialise to default value
employeename: null, // can initialise to default value
employeeteam: null // can initialise to default value
}
})
Your controller code can contain the values for employeeid
, employeename
, employeeteam
as $scope
variables like,
$scope.idVal = 'id';
$scope.nameVal = 'name';
$scope.teamVal = 'team';
Your HTML will be as follows,
<a ui-sref="detail({
employeeid:idVal,
employeename: nameVal,
employeeteam: teamVal
})"> Details state </a>
Upvotes: 4