Question

I have two controllers as follows.

   .when('/list_persons', {
      templateUrl: 'views/list_persons.html',
      controller: 'topBarController',
      activetab: 'list_persons'
    })
    .when('/register_person', {
      templateUrl: 'views/register_person.html',
      controller: 'topBarController',
      activetab: 'register_person'
    })

In the /list_persons view I have a table with person. In the table I would like to create a icon for editing a person. When the user clicks on this icon I would like to redirect to /register_person view. I would also like add some data to the redirect(the person to edit). How can I accomplish this?

Edit: tobarController is just responsible for highlighting elements in the header based on which side you are. There are other controllers on these templates doing the main work.

Était-ce utile?

La solution

You could use routeParams for this. Just add the id of the person to edit to the path and change your routes as follows:

 .when('/list_persons/:personId', {
  templateUrl: 'views/list_persons.html',
  controller: 'topBarController',
  activetab: 'list_persons'
})

Then, within your topBarController, you can inject the $routeParams-Service which will contain the personId:

[...].controller('topBarController', function($scope, $routeParams){
    $scope.personId = $routeParams.personId;
}

If you have all your persons stored inside a Service or something, it gonna be easy to retrieve the person to edit just by the id.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top