Ionic PopUp : TypeError: Cannot read property 'confirm' of undefined


#1

Hi guys, I would like to code a simple “confirm ionic pop up”, but I had this issue that I can’t solve. I’m sure if you take a look you’ll find it out, because now it’s like I was totally blind against it …

TypeError: Cannot read property ‘confirm’ of undefined

Here is my “directive.js” file (from ionic creator) :

// Here is the start of my "directive.js" file, I have one directive and 3 controllers

var myApp = angular.module('app.directives', [])

myApp.directive('activePageHighlight', ['$rootScope', '$state', function($rootScope, $state){
  
// Something else
  
}]);

// Here is my controller

myApp.controller('MainCtrl', ['$scope', function ($scope, $ionicPopup, $timeout) {
  
$scope.info = function(){
    
var confirmPopup = $ionicPopup.confirm({
    // Here I tried to add $scope, but I'm not sure if is it usefull
    scope:$scope,
    title: 'Consume Ice Cream',
    template: '<button class="button button-primary" ng-click="info()">Confirm</button>'
   });

   confirmPopup.then(function(res) {
     if(res) {
       console.log('You are sure');
     } else {
       console.log('You are not sure');
     }
   });
 };

}]);

Here is my “html template” file (from ionic creator too) :

<div ng-controller="MainCtrl">
  
    <button ng-click="info()" class="calm button-block">Info 1</button>
  
</div>

Thank you !


#2

I solved the problem : forgot to add $ionicPopup and $timeout :

myApp.controller(‘MainCtrl’, [’$scope’, ‘$ionicPopup’, ‘$timeout’, function ($scope, $ionicPopup, $timeout) {

:wink: