Quantcast
Channel: Ionic Framework - Ionic Forum
Viewing all articles
Browse latest Browse all 49166

View is loaded before function call to Factory is returned with value

$
0
0

@oasisari wrote:

Hello, I'm new to ionic and I'm having problem with ionic-view not being updated due to a service function call. If I write the content of the function in the controller then the view is updated fine.

In the controller, if I use this, my view is not updated with the userName. "Chats" is the factory name.

  Chats.getUserName().then(function (result) {
    $scope.userName = result;
  });

If I write the content of getUserName() in the controller, then my view is updated successfully with the userName:

  $cordovaFile.readAsText(cordova.file.dataDirectory, $scope.localUserFile)
  .then(function (result) {
    $scope.user = JSON.parse(result);
    $scope.userName = $scope.user.name;
 });

My view:

<ion-view view-title="Friend Zone" view-cache="false">
  <ion-content padding="true">
    <div class="item item-text-wrap" ng-show="userName" ng-cloak>
      Hello, <span ng-bind="userName"></span>!
</div></ion-content></ion-view>

I really want to use Service / Factory but I just can't get it working this time. It seems that the Factory is "slow" in returning the value, hence the view is updated before $scope.userName is updated with the returned value from Factory.

Please help and point me in the right direction.

Thank you

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 49166

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>