Problematic transition by ionic appearance

I call the API and return the response to bind to $ionicView.beforeEnter. However, when the entered view is entered, sometimes I load the view, but the data is not connected until a few seconds later, especially in case of poor network connection. How to solve this problem?

Will it be asynchronous due to my API call?

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>
+1
source share
1 answer

, - ApiMethod. , $ionicLoading. "" , . , , .

:

angular.module('app').controller(function($scope, ApiMethod, $ionicLoading) {

    $scope.show = function() {
        $ionicLoading.show({
            template: 'Loading...'
        }).then(function(){
            console.log("The loading indicator is now displayed");
        });
    };
    $scope.hide = function(){
        $ionicLoading.hide().then(function(){
            console.log("The loading indicator is now hidden");
        });
    };

    $scope.$on("$ionicView.beforeEnter", function(event, data){
        // Show loading
        $scope.show();
        ApiMethod.GetFormInfo().$promise.then(function (res) {
            $scope.res = res;
            // Hide loading
            $scope.hide();
       }, function (errRes) {

       })
    });
});

: $ionicLoading

+1

All Articles