$ionicPopus is throwing error


#1

Hello there,

I have been getting error whenever I press Next button which has function as below:-

if(condition1)
{

var popup1 = $ionicPopup,alert({
scope: ‘enter name’,
template : ’ ',
title: ‘Error’,
buttons: [{
text: ‘Ok’,
onTap; function (e) { return 0;}
}]

});

popup1.then(function (res) {
console.log(‘sa’);
});
}

it is throwing an error as below described:-

ionic.bundle.js:26799 TypeError: (options.scope || $rootScope).$new is not a function
at Object.createPopup [as _createPopup] (ionic.bundle.js:56766)
at showPopup (ionic.bundle.js:56848)
at Object.showAlert [as alert] (ionic.bundle.js:56919)
at ChildScope.$scope.Next1 (controllers.js:204)
at fn (eval at compile (ionic.bundle.js:27643), :4:206)
at ionic.bundle.js:65429
at ChildScope.$eval (ionic.bundle.js:30400)
at ChildScope.$apply (ionic.bundle.js:30500)
at HTMLButtonElement. (ionic.bundle.js:65428)
at defaultHandlerWrapper (ionic.bundle.js:16792)


#2

Hi!

you’re not initializing this correctly. First of all: remove scope. In template you put your “body” message. You could leave that empty though.

Here is a working code example.

function showAlert() {
  var alertPopup = $ionicPopup.alert({
    title: 'Don\'t eat that!',
    template: 'It might taste good',
    buttons: [
      {text: '<b>Yeah</b>, ok then'}
    ]
  });

  alertPopup.then(function(res) {
    console.log('Thank you for not eating my delicious ice cream cone');
  });
}

The documentation is also a very good source for answers. You may want to check it as well:

http://ionicframework.com/docs/api/service/$ionicPopup/