javascript - Angular JS assign to scope from Ajax then calculate -


i need calculations data ajax , present result.

data.getorder(2)             .success(function(data)             {              $scope.contactlist = data;               }) 

then have :

$timeout(function(){          angular.foreach($scope.contactlist,function(value,index){             ...do         })      }, 2000); 

it works fine best way it?? there no other way make sure when work $scope.contactlist wont null?

the ajax call result :

[{"amount":150,"percent":15},{"amount":150,"percent":15}] 

i need cycle ,

cycle 1 - amount * percent = total  cycle 2 - amount * percent = total2     $cope.grandtotal = total+total2 

i know could, example use custom filter using ngtable , cant right.

 <table ng-table="tableparams" class="table">                 <tr ng-repeat="user in $data">                     <td data-title="'pedido'" sortable="'order_id'">                         [[user.order_id]]                     </td>                     <td data-title="'producto'" sortable="'product'">                         [[user.product]]                     </td>                     <td data-title="'qty'" sortable="'amount'">                         [[user.amount]]                     </td>                      <td data-title="'descuento'" sortable="'percent'">                         % [[user.percent]]                     </td>                     <td data-title="'total pagar'" sortable="'percent'">                           $  [[ (user.amount * user.cost)- (user.amount * user.cost)* 0.15]]                     </td>                 </tr> 

thanks

update

data.getorder(2)             .success(function(data)             {              $scope.contactlist = data;                     $scope.load = year+" "+nam;                 // processdata()               //              }).then(function(){               processdata()              })  function processdata() {             angular.foreach($scope.contactlist, function(value, index) {                 alert(value.amount);             });         } 

the above works fine, done right? how add error function?

using timeout cause problems. know when data available, process then.

data.getorder(2)     .success(function(data) {          $scope.contactlist = data;     })     .error(function(err) {          // handle error.     })     .then(processdata);  function processdata() {     angular.foreach($scope.contactlist, function(value, index) {         alert(value.amount);     }); } 

Comments

Popular posts from this blog

How to provide Authorization & Authentication using Asp.net, C#? -

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

How to use Authorization & Authentication in Asp.net, C#? -