javascript - AngularJS databinding not updating until arbitrary event is fired -


so can't make fiddle out of problem due client restrictions in general have 2 way data binding string won't update on html side until arbitrary event fired(once buttons clicked update, trivial buttons toggle visibility update it). if set $scope.verifiedaddressed1 equal "verifying..." data bind, once change "1234 cherry lane", not update until click button on webpage. html side of things looks

<p>{{verifiedaddressed1}}</p> // "verifying..." 

while angular code looks following:

$scope.verifiedaddressed1 = "verifying..."; $scope.verifyaddress = function(isvalid){     if(isvalid){        $.get( "validurl.com", function( data ) {                 $scope.verifiedaddressed1 = data[0].validdata;                 console.log($scope.verifiedaddressed1);         //"1234 cherry lane"             });         }, 400);         settimeout(function() {             console.log($scope.verifiedaddressed1);             //"1234 cherry lane"          }, 700);     } } 

has seen weird bugs before? i've been working angularjs little while , know there still lot of little bugs here , there around button clicks , not, sure has nothing button event since button on page activate 2 way binding update on verifiedaddressed1

you should use angular's services keep scope updating when expect to. instead of $.get, use $http.get, , instead of settimeout, use $timeout (but when need work outside of update loop). there's never reason call $scope.$apply - if use angular properly, scope stay updated.

myapp.controller('mycontroller', ['$scope', '$http',   function ($scope, $http) {     $scope.verifyaddress = function (isvalid) {       if (isvalid) {           $http.get('validurl.com')             .success(function (data) {               //...             })             .error(function (data, status) {               //...             });       }     }; }]); 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -