1

I have TWO functions.

One hides a modal when the 'close' button is clicked The other function swipes right and changes the modal to another state/view.

I am having an issue with the modal NOT 'hiding' when the user swipes to the new state. I can see that it works but the modal remains on display and I was thinking that the best way to approach this is by chaining my two functions? Is this the correct terminology?

The TWO functions..

HIDES the modal

$scope.closetripInfo = function() {
    $scope.modal.hide();
  };

SWIPES right to reveal new .state

$scope.onSwipeRight = function() {
  $state.go('app.current-trip');
}

This worked! BUT.. What I was thinking of doing is plugging in my exciting closetripInfo function into the onSwipeRight Like so:

$scope.onSwipeRight = function() {

  $scope.closetripInfo();  
  $state.go('app.current-trip').closetripInfo();
}

It works BUT it does not look right to me and I am getting an error.. I haven't been successful on doing it correctly. Perhaps is not that simple. I also think that I might need to be aware of best practices like promises?

THE ERROR

TypeError: $state.go(...).closetripInfo is not a function at Scope.$scope.onSwipeRight

Any advice or resources would be greatly appreciated.Thank you!

0

1 Answer 1

5

You can use AngularJS promises to run functions asynchronously. Promises in AngularJS are provided by the built-in $q service.You can read upon it here.

$scope.onSwipeRight = function() {
  var deferred = $q.defer();
  deferred.resolve('res');

  $state.go('app.current-trip');

  // We return a promise
  return deferred.promise;
}


onSwipeRight().then(function(res) {
   // Success callback
   $scope.closetripInfo();
},null);

Here is a fiddle on using the $q service. Also this is a good blog post where promises are explained as a cartoon.

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

1 Comment

Midhun! This is great and exactly that I was thinking however I did not know the proper way to execute this! Thank you!

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.