binoculars
binoculars

Reputation: 2274

Chaining events in AngularJS

I'm trying to call a function after a popup automatically closes after 1 second. This is my code:

$timeout(function() {
  var closeit = myPopup.close();
  closeit.then(function() {
    $scope.dosomething();
  });
}, 1000);

The dosomething function is never called. I'm new to AngularJS, anyone who can help me with this?

Upvotes: 1

Views: 459

Answers (1)

Ori Drori
Ori Drori

Reputation: 191936

$ionicPopup - $ionicPopup.show(options) documentation:

Returns: object A promise which is resolved when the popup is closed. Has an additional close function, which can be used to programmatically close the popup.

var myPopup = show(options); // when you create a popup with $ionicPopup, you get a promise for the close event

myPopup.then(function() { // add a callback to the promise when it's fulfilled - ie the popup was closed
  $scope.dosomething();
});

$timeout(function() {
  myPopup.close();
}, 1000);

Upvotes: 2

Related Questions