0

我想编写一个简单的“确认离子弹出窗口”,但我遇到了无法解决的问题。我敢肯定,如果您看一下就会发现,因为现在我好像完全对它视而不见...

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>

谢谢 !

4

2 回答 2

0

这一行:

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

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

myApp.controller('MainCtrl', ['$scope', '$ionicPopup', '$timeout', function ($scope, $ionicPopup, $timeout) {
于 2016-12-06T09:57:57.057 回答
0

您只是注入$scope作为控制器的依赖项,也添加其余部分,它应该可以工作。

myApp.controller('MainCtrl', ['$scope', '$ionicPopup', '$timeout', function ($scope, $ionicPopup, $timeout) { 
// ... 
}])
于 2016-12-06T09:57:58.150 回答