javascript - Angular Ajax temporaly variables -
i'm trying of number of records return ajax json file when i'm trying of print number records outside ".success block" don't value exits inside ".success block"
example:
var total = 0; $http.get("json/noticias.json")   .success(function(response) {     $scope.lista = response;     total = response.noticias.length;     alert(total);//print 3   });  alert(total);//print 0 i need print 3 in second 1 also.
angularjs uses promise module called $q. have use then() or catch() json data after success
var total = 0;  $http.get("json/noticias.json") .success(function(response) {  $scope.lista = response;  response.total = response.noticias.length; ;  alert(total);//print 3   }).then(  function( response ) {  alert(response.total); //print 3  });  i hope help
Comments
Post a Comment