I’m using the ionic sidemenu template. Everything works except when I put modal.show inside the AppCtrl controller an undefined error was thrown. Basically what I want to do is on startup check if a user is already logged in, if not, show the login modal. Here’s my code:
.controller('AppCtrl', function ($scope, $ionicModal, $timeout, $ionicLoading) {
// Form data for the login modal
$scope.loginData = {};
$scope.currentUser = {};
// Ionic loading screen
$scope.showLoading = function () {...};
$scope.hideLoading = function () {...};
// Create the login & register modal that we will use later
$ionicModal.fromTemplateUrl('templates/login.html', {
scope: $scope
}).then(function (modal) {
$scope.modal = modal;
});
// Show/close login form modal
$scope.closeLogin = function () {
$scope.modal.hide();
};
$scope.login = function () {
$scope.modal.show();
};
// Log out the current user
$scope.logout = function () {...};
// Perform the login action when the user submits the login form
$scope.doLogin = function () {...};
// Send SMS for verification
$scope.doSendSMSCode = function () {...};
// Perform user registration action
$scope.doReg = function () {...};
// Check if currentUser exists if not show sign in page. THIS IS WHERE THE ERROR IS THROWN
showLoginOnNullUser = function () {
if (!$scope.currentUser)
$scope.login();
};
showLoginOnNullUser();
})
Now the error console output is:
Error: 'undefined' is not an object (evaluating '$scope.modal.show')