$ionicPopup.prompt does not work for Guide example


#1

This is a code snippet taken from the Guide:

...
  // Try to create the first project, make sure to defer
  // this by using $timeout so everything is initialized
  // properly
  $timeout(function() {
    if($scope.projects.length == 0) {
      while(true) {
        var projectTitle = prompt('Your first project title:');
        if(projectTitle) {
          createProject(projectTitle);
          break;
        }
      }
    }
  });
...

If I change the code to use $ionicPopup.prompt (instead of a plain javascript prompt) it does not work at all:

...
      // Try to create the first project, make sure to defer
      // this by using $timeout so everything is initialized
      // properly
      $timeout(function() {
        if($scope.projects.length == 0) {
          while(true) {
            $ionicPopup.prompt({
              title: 'Project Title',
              content: 'Enter your project title',
              inputType: 'text',
              inputPlaceholder: 'Your first project title'
            }).then(function(projectTitle) {
              createProject(projectTitle);
              break;
            });
          }
        }
      });
    ...

I also updated this line to include $ionicPopup:
.controller('TodoCtrl', function($scope, $timeout, $ionicModal, $ionicPopup, Projects) {

Any ideas?


#2

Have you tried returning the popup? That’s how I’ve been using it successfully (but haven’t moved to beta yet).


#3

What do you mean by returning the popup?
Can you send a code sample?


#4

Looks like it doesn’t need to be returned:


#5

You don’t need the while loop. $ionicPopup.prompt returns a promise, so createProject is called once the popup completes.