Hi, I am facing problem with $ionicLoading. $ionicLoading.hide() is not working inside .then. The error on console says “$ionicLoading.hide is not a function” I have verified that there is no typo. And I can safely say that $ionicLoading is correctly injected as $ionicLoading.show() is working.
$scope.signin = function() {
var credentials = {
ph_no: $scope.ph_no,
password: $scope.password
};
$ionicLoading.show({
template: '<ion-spinner icon="bubbles"></ion-spinner><br/>Loading...',
delay: 100
});
$auth.login(credentials).then(function(data) {
// If login is successful, redirect to the offers state
$ionicLoading.hide();
$state.go('app.offerslist', {});
}, function(error) {
console.log("promise error");
});
};
It’s my signin function which gets called when user submits signin form. Please help. Thanks you.
$auth.login(credentials).then(function(data) {
// If login is successful, redirect to the offers state
$rootScope.$broadcast('app.loggedIn');
}, function(error) {
console.log("promise error");
});
Use the code above in your signin function, you will now broadcast a successful sign in throughout your app.
Use the code below (put it on the same level as a controller) to catch the broadcast and act on it.
.run(['$rootScope', '$ionicLoading', function ($rootScope, $ionicLoading) {
// Event listern on the broadcast "LoggedIn".
$rootScope.$on('app.loggedIn', function (event) {
$ionicLoading.hide();
$state.go('app.offerslist', {});
});
}])
.controller("etc........Remove this line"
Don’t forget to inject $rootScope in your controller otherwise it’s unavailable. I would have done it for you but you did not provide the controller just the sign-in function.
Thanks a lot for your reply. I tried that code but it is not working. $ionicLoading.hide() is not working. You can check my full code at https://gist.github.com/ssd532/1e4ab76a2f3b17bcb7cd Even after transiting to the next state the loading bubbles from the signin keep on spinning. The error $ionicLoading.hide is not a function is gone though.
I put the code inside .controller but to no avail. You are correct, the code was not executing at all inside .run but in .controller it has again started throwing the same $ionicLoading.hide is not a function error.
The position of $ionicLoading and $ionicPopup was not correct which messed up the things. Correcting the positions solved the problem, but I am still not getting why $ionicLoading.show() was working.
postulates a mapping between names and javascript objects (services). AngularJS requires them to be on order to map them correctly.
So what you did was to map the name ‘$ionicLoading’ to the object $ionicPopup and vice versa. You probably could have called $ionicPopup.hide() with some success here