0

In my index.html within ng-repeat I have a tag like this

<li><a ng-click="viewJobs(employer)">View Job Listing</a></li>

then in my controller I do

$scope.viewJobs = function(user){
    $location.path('/employers/jobs/' + user.user.id);
}

My route config

.when('/employers/jobs/user_guid',{
        templateUrl : '/myTemplate/employers/jobs.html',
        controller : 'employersJobController'
    })

When I click on the link it go to http://localhost/#/, I wonder what is my mistake.

Alice Xu
  • 533
  • 6
  • 20

1 Answers1

0

The route config should be (and the param should start with a :),

.when('/employers/jobs/:id',{
        templateUrl : '/myTemplate/employers/jobs.html',
        controller : 'employersJobController'
    })

Note : the parameter you are passing from the controller and the routing param must be same (by name).

for,

$location.path('/employers/jobs/' + user.user.myId);

the route config will be,

.when('/employers/jobs/:myId',{
        templateUrl : '/myTemplate/employers/jobs.html',
        controller : 'employersJobController'
    })
Md Ashaduzzaman
  • 4,032
  • 2
  • 18
  • 34
  • One question Ashad, what if I want to hide the param? it's a guid, so I think it shouldn't exposed to the public. – Alice Xu Aug 30 '15 at 05:25
  • in that case you can't have a state that contains id. Make a new state without id and call it. like, `/employes/jobs/detail` and use `service` to share data between controllers. – Md Ashaduzzaman Aug 30 '15 at 05:33
  • a quick search got me this http://stackoverflow.com/questions/20181323/passing-data-between-controllers-in-angular-js – Md Ashaduzzaman Aug 30 '15 at 06:13