angularjs - Angular newbie : $scope variable need to be used twice to refresh a textarea -


i try angularjs first time , i'm stuck on problem.

in debugger see scope variable '$scope.xml' correctly updated, display needs second pass (second click) refresh.

here plunker see problem : http://plnkr.co/edit/9pjsgedqwjc6nmzhcejv

i'm looking in documentation can not find track understand did not well

thank's lot !

<!doctype html> <html ng-app="testangularjs"> <head> <script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script> <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.0.6/angular.min.js"></script> </head> <body> <div ng-controller="testxml"> <div>xml<br/><textarea cols="60" rows="15" ng-model="xml" name="xml">{{xml}}</textarea></div>  <div><button ng-click="listtypdoc()">list !</button><br/>  <br/><button ng-click="clearxml()">clear</button></div> </div>  <script type="text/javascript">  var app = angular.module('testangularjs', []);   app.controller('testxml', function($scope){    $scope.url = 'listetypdoc.txt';      $scope.listtypdoc = function() {          $.ajax({                 type:"get",                 url: $scope.url,                 xhrfields: {                    withcredentials: false                 },                 crossdomain: false             }).done(function ( data ) {                $scope.xml = data;                debugger;           });          };          $scope.clearxml = function() {         $scope.xml = '';          };      })   </script> </body> </html> 

because using request outside angularjs, need call $apply() after setting data $scope.xml. take in apply method:

http://docs.angularjs.org/api/ng.$rootscope.scope

but it's better use services angularjs provides instead of using jquery.


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -