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);
       .....}
4
  • You want to run that $scope.edit function if you have some params in the url? Commented Jul 12, 2016 at 10:18
  • @chinni Yes.. and pass the parameter values to that method Commented Jul 12, 2016 at 10:35
  • yes you can but not sure is the best idea Commented Jul 12, 2016 at 10:37
  • check this question i answered that and its the same stackoverflow.com/questions/38300146/… Commented Jul 12, 2016 at 10:43

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.