Hello, im all new to using Ionic and so far i love.
My login works great, but i wish it would try to log in by auto when opening the app, if the fields are set already using the $localstoarge, are there any way to activate the $scope.doLogin from my controller?
.controller('loginCtrl', ['$scope', '$state', '$ionicHistory', '$localstorage', '$http', 'Auth', function ($scope, $state, $ionicHistory, $localstorage, $http, Auth) {
// Form data for the login modal
$scope.loginData = $localstorage.getObject("login");
// Perform the login action when the user submits the login form
$scope.doLogin = function () { .... }
}
Best regards
Mathias, a new developer
Instead of auto completing the fields, could you not store the session of a successful login, then in your app.run()
check for a user session and restore the required user details, bypassing the need to go through .doLogin
?
You should move the login logic into a service and use the controller to call the methods exposed when required.
I need it to go though the login, because it would be getting some data back alongside if its logged in or not.
But ill try and make it into service.
Thank you
By moving your login logic into a service you can re-use and utilise it elsewhere and in your case it’s appropriate to do so.
1 Like
ah okay. Thank you, ill be looking into that then
Seems to make my life much easier now.
Thanks for the help Delta