0

i can use two function on ng-init ? how? i've tried an setTimeout to run an function to open a modal and after a time period , it call the function that closes the modal , but does not work ...

like this :

ng-init="setTimeout(closeModal, 2000) && openModal();"

both functions are inside the controller:

function ($scope, $stateParams, $ionicModal, $window, $timeout ) {




  $ionicModal.fromTemplateUrl('modal.html', {
    scope: $scope,
    animation: 'slide-in-up'
  }).then(function(modal) {
    $scope.modal = modal;
  });
  $scope.openModal = function() {
      alert("funcionou!");
    //$scope.modal.show();
      $timeout(function(){
$scope.modal.show(); 

},0)

  };

  $scope.closeModal = function() {
    $scope.modal.hide();
  };
  // Cleanup the modal when we're done with it!
  $scope.$on('$destroy', function() {
    $scope.modal.remove();
  });
  // Execute action on hide modal
  $scope.$on('modal.hidden', function() {
    // Execute action
  });
  // Execute action on remove modal
  $scope.$on('modal.removed', function() {
    // Execute action
  });

2 Answers 2

1
ng-init="initialFunction()"

Inside your controller write:

function initialFunction(){
$timeout(closeModal, 2000); openModal();
}
Sign up to request clarification or add additional context in comments.

Comments

0

First use $timeout instead of setTimeout.

second use ; instead of && at the end of each function when calling multiple functions

ng-init="$timeout(closeModal, 2000); openModal();"

add this to your controller

$scope.$timeout = $timeout; 

inject the $timeout to the controller also

2 Comments

run only the openModal(); :/
@Mr.Malaka no prob bro

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.