Tech Kid
Tech Kid

Reputation: 577

AngularJS: How to send parameter with $location.path()

I'm trying to create redirection call in controller with some numeric parameter or argument but I'm failded. I'm using this code

$location.path('/tastlist/:$rootScope.job_id');

also i'ave tried

$location.path("/tastlist/",$rootScope.job_id');

My route is as follows:

$routeProvider.when('/tastlist/:job_id', {templateUrl: 'partials/list-task.html', controller: 'tasklistCtrl'});

Route is working well in my html for this code:

<a ng-click="go('/tastlist/' + job.id)">back to task list</a>

I want to create automatic redirection in controller via $location.path() or via anyother. Please help me out for this..

Upvotes: 1

Views: 4222

Answers (1)

Gustav
Gustav

Reputation: 3586

Your second try is almost right

$location.path("/tastlist/" + $rootScope.job_id);

you are building the url with the actual value you want to set. if you'd do

 $location.path("/tastlist/4");

job_id in $stateParams would get set to 4

Upvotes: 3

Related Questions