0

We have functionality where in we have make reservation editable,when user clicks on link from email.

Currently user can browse in the website and lookup based on the email address and then click on edit to make changes to reservation,so the edit functionality is like a child only action.

<button ng-if="!reservation.editing" test-id="reservations-reservation-edit-button" ng-click="edit(reservation)" class="btn btn-link change-link details-edit-reservation-link">Edit</button>

The email link will have parameters like "RId","UserId" ...

The question is how can we invoke the edit action directly, based on the parameter passed. Below is the snippet of current $state.go

 sp.state('reservations', {
    url: '/reservations?e&getDetail&edit',
    templateUrl: 'src/reservations/template.html',
    data: {
      backState: "back",
      shortTitle: "Reservations"
    }

Can we make any changes in $state, so that we can do conditional routing and then invoke the edit and edit functionality function snippet looks like this

 $scope.edit = function(reservation){
      scrollToTop(true);
       .....}
Hafeez Khan
  • 427
  • 2
  • 6
  • 22

1 Answers1

1

As far as I understand your problem, you can solve it using $stateParams

Your controller:

yourApp.controller("YourCtrl"), function($scope, $stateParams) {
    var edit = $stateParams.edit;
    var getDetail = $stateParams.getDetail;
    var e = $stateParams.e;

    $scope.edit = function (params) {
        ...
    };

    if(edit && e) { // have whatever condition you want for enabling editing
        // run the function and pass the stateParams to the function
        $scope.edit($stateParams);
    }
});

Note that $stateParams will be a json with keys to be the param names and values to be the param values in the url. Please refer the official docs for more info.

Hope this solves the issue.

Chinni
  • 1,199
  • 1
  • 14
  • 28