1
    $scope.modelTmp = {
        appData.getAppDataItem({'@key': 'last_news_sync_date'}).then( function (x) {
                    $scope.modelTmp.useMobileDataTmp = x; })
        console.log($scope.modelTmp.useMobileDataTmp);

I want to assign x to useMobileData. Please help me to do it.

Mr_Perfect
  • 8,254
  • 11
  • 35
  • 62

2 Answers2

3

You can't assign it synchronously, you can only do so in the callback:

$scope.modelTmp = {}

appData.getAppDataItem({'@key': 'last_news_sync_date'}).then(function (x) {
    $scope.modelTmp.useMobileDataTmp = x;
});
deceze
  • 510,633
  • 85
  • 743
  • 889
  • Once you go out of the `.then()` it is `undefined` I think. I am getting it as `undefined`. See my edited code. The `console()` message is `undefined` – Mr_Perfect Sep 19 '16 at 04:54
0

You're going to want to wait until the promise is resolved and then inside the callback assign it to the modelTmp object. At the moment you're just assigning the promise to the modelTmp.useMobileDataTmp.

See below for how to assign in the callback

$scope.modelTmp = {};

appData.getAppDataItem({'@key': 'last_news_sync_date'}).then( function(x) {
  $scope.modelTmp.useMobileDataTmp = x;
})
Joe OB
  • 11
  • 2