I call API and return the response for binding in $ionicView.beforeEnter
. However, when the view is entered, sometimes I got the view loaded but the data is not being bind until few seconds later, especially in a bad network connectivity. How could this issue be solved?
Would this because of my API call is asynchronous?
angular.module('app').controller(function($scope, ApiMethod) {
$scope.$on("$ionicView.beforeEnter", function(event, data){
ApiMethod.GetFormInfo().$promise.then(function (res) {
$scope.res = res;
}, function (errRes) {
})
});
});
<ion-content>
<form name="form">
<div class="list">
<label class="item item-input">
<input type="text" placeholder="First Name" ng-model="res.firstName">
</label>
<label class="item item-input">
<input type="text" placeholder="Last Name" ng-model="res.lastName">
</label>
<label class="item item-input">
<textarea placeholder="Comments" ng-model="res.comments"></textarea>
</label>
</div>
<button type="submit">Submit</button>
</form>
</ion-content>
Yes, there is a flicker because of the pause asynchronous
ApiMethod
call. To gracefully handle this inside my Ionic application I use$ionicLoading
. This will "freeze" the user from moving around until the data has been loaded. I believe it is better to notify them of the loading then make them question a blank view.Implemented:
Reference: $ionicLoading