Reputation: 410
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 code :
// 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');
}
});
};
}]);
<div ng-controller="MainCtrl">
<button ng-click="info()" class="calm button-block">Info 1</button>
</div>
Thank you !
Upvotes: 0
Views: 1517
Reputation: 10874
You're only injecting $scope
as dependency for your controller, add the rest too and it should work.
myApp.controller('MainCtrl', ['$scope', '$ionicPopup', '$timeout', function ($scope, $ionicPopup, $timeout) {
// ...
}])
Upvotes: 0
Reputation: 13997
This line:
myApp.controller('MainCtrl', ['$scope', function ($scope, $ionicPopup, $timeout) {
You forgot to inject the $ionicPopup
and $timeout
service:
myApp.controller('MainCtrl', ['$scope', '$ionicPopup', '$timeout', function ($scope, $ionicPopup, $timeout) {
Upvotes: 0