我想编写一个简单的“确认离子弹出”,但我有这个问题我无法解决。我敢肯定,如果你看看你会发现它,因为现在它就像我完全失明了...
TypeError:无法读取未定义的属性'confirm'
这是我的代码:
// 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 :(得分:0)
这一行:
myApp.controller('MainCtrl', ['$scope', function ($scope, $ionicPopup, $timeout) {
您忘记注入$ionicPopup
和$timeout
服务:
myApp.controller('MainCtrl', ['$scope', '$ionicPopup', '$timeout', function ($scope, $ionicPopup, $timeout) {
答案 1 :(得分:0)
您只是将$scope
作为依赖项注入控制器,添加其余部分并且它应该可以正常工作。
myApp.controller('MainCtrl', ['$scope', '$ionicPopup', '$timeout', function ($scope, $ionicPopup, $timeout) {
// ...
}])