Two way binding not refreshing


#1

Hi I am pragmatically changing the object values but its not updating on page showing brackets( {{ values }} ).But when i touch the screen it refreshed and show the result…


#2

That’s interesting. However, you need to give us something to work with here.

  • Ionic Version?
  • Device Platform
  • Device Version
  • Code sample

#3

Is your value definitely an option and not a primitive example? I found in the first few days with Angular that I was missing that key concept.

Anything happen if you use: $scope.$apply()


#5

instead of calling $apply wrap the variable modification with a $timeout function, because calling directly to $apply can interfere with the angular digest cycle look here

$timeout(function() {
    myVariable += 1;
});

#6

Ionic version latest beta 4
Device Android 4,3
Samesung S5

controller(‘MyCtrl’, [’$scope’, ‘$stateParams’,’$ionicPopup’, ‘DataProvider’, ‘$http’, function ($scope, $stateParams, $ionicPopup, DataProvider, $http) {
//------------------------------------get message body--------------------------------------------
$scope.GetMessagesBody = function()
{
$scope.EmailBody = somehtml;
}
$scope.GetMessagesBody();

//--------------------------------------------------------------------------------------
$scope.MoveNext = function (nextHTML) {     
            $scope.EmailBody = nextHTML;                   
}

}

Email body refreshing only after touching device


#7

Unfortunately, that code sample is not really helping. We can’t see how the data is fetched. Was it asynchronously gathered? Did you use a callback function or a promise? Was it all in the AngularJS digest? If it was not in the digest, the scope will not update properly.

I’m afraid this is too complex to figure out from a code snippet. I’d suggest you post a CodePen sample that demonstrates where / how the controller is getting the data.


#8

What is you change $scope.EmailBody = somehtml; to

$scope.EmailBody = {body: somehtml};

and then refer to it as $scope.EmailBody.body or EmailBody.body as relevant?


#9

i am getting json data from server using $http and json response data contains field like
somehtml = { FromName : frm , MessageCode : svc , Subject : subject,Date :date , Msg : html }

and assigning to $scope.EmailBody =somehtml;

but now i put global exception handling and it showing below error…bad parse


#10

You said you are

and assigning to $scope.EmailBody =somehtml;

but your view shows {{body.FromName}} and {{body.EmailBody}}. Shouldn’t those be {{body.EmailBody}} and {{body.MessageCode}}

Also I’m assuming you are trying to put the raw email HTML into your view as well?

If so, you need to look at $sanitize. https://docs.angularjs.org/api/ngSanitize/service/$sanitize

Be sure to read the very top part about whitelisting.