我想编码一个简单的"确认离子弹出",但是我有一个无法解决的问题。我敢肯定,如果您看一下,您会发现它,因为现在就像我完全对它视而不见...
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>
谢谢!
此行:
myApp.controller('MainCtrl', ['$scope', function ($scope, $ionicPopup, $timeout) {
您忘了注入$ionicPopup
和$timeout
服务:
myApp.controller('MainCtrl', ['$scope', '$ionicPopup', '$timeout', function ($scope, $ionicPopup, $timeout) {
您只是将$scope
注射为控制器的依赖项,也要添加其余的,并且应该工作。
myApp.controller('MainCtrl', ['$scope', '$ionicPopup', '$timeout', function ($scope, $ionicPopup, $timeout) {
// ...
}])