2016-12-06 56 views
-1

我想編寫一個簡單的「確認離子彈出」,但我有這個問題,我無法解決。我敢肯定,如果你看一看,你會發現它,因爲現在它就像我反對完全失明......Ionic PopUp:TypeError:無法讀取未確定的屬性'確認'

類型錯誤:未定義

這裏無法讀取屬性「確認」是我的代碼:

// 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>

謝謝!

回答

0

這條線:

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

你忘了注入$ionicPopup$timeout服務:

myApp.controller('MainCtrl', ['$scope', '$ionicPopup', '$timeout', function ($scope, $ionicPopup, $timeout) { 
+0

我好笨!感謝很多人的工作! :) – Memphis

0

你只是在注射$scope作爲依賴於你的控制器,加上休息過,它應該工作。

myApp.controller('MainCtrl', ['$scope', '$ionicPopup', '$timeout', function ($scope, $ionicPopup, $timeout) { 
// ... 
}]) 
+0

也謝謝你! :) – Memphis

相關問題