I am trying to open a modal from a controller but I get an error can’t read property ‘show’ of undefined
.controller('LoginCtrl', function($scope, $state, $ionicModal, Login) {
$scope.user = [];
$scope.modalMsg = [];
$ionicModal.fromTemplateUrl('modal.html', {
scope: $scope,
animation: 'slide-in-up'
}).then(function(modal) {
$scope.modal = modal;
});
$scope.openModal = function() {
$scope.modal.show();
};
$scope.closeModal = function() {
$scope.modal.hide();
};
$scope.$on('modal.hidden', function() {
$scope.modal.remove();
});
$scope.$on('modal.removed', function() {
// Execute action if needed
});
$scope.login = function(user) {
if (Login.validate(user)) {
alert("YAY!");
} else {
$scope.modalMsg.title = "ERROR!";
$scope.modalMsg.content = '<p>Please re-enter your username and password.</p>';
$scope.openModal();
}
};
})
So I have a validate and on not entering a username or pw it fails. so $scope.openModal() is happening, but the modal is undefined, how am I doing it wrong???