AngularJS sum of value with if condition -


i have problem in angularjs view. have values if condition , want calculate sum. working before if condition after adding if condition, problem occurred , showing result nan. here code.

<div ng-if = "nnn == 'yes'"> <h3>sale roakker (naam)</h3> <div class="card-content table-responsive">     <table class="table table-bordered pagin-table">         <thead>             <tr>                 <th>date</th>                 <th>name</th>                 <th>item name</th>                 <th>total</th>                               </tr>         </thead>         <tbody>             <tr ng-repeat="x in sales_items_detail">                 <td>{{ x.date }}</td>                 <td>{{ x.name }}</td>                 <td>{{ x.item_name }}</td>                 <td>{{ (x.amount).tofixed(2) }}</td>             </tr>         </tbody>         <tfoot>             <tr>                 <td colspan="2"><strong>total</strong></td>                 <td><strong>{{amount_sale = amounttotal(sales_items_detail)}}</strong></td>               </tr>                                     </tfoot>     </table>                         </div> </div> <div ng-if = "nnn == 'not'"> <h3>sale roakker (naam)</h3> <div class="card-content table-responsive">     <table class="table table-bordered pagin-table">         <thead>             <tr>                 <th>date</th>                 <th>name</th>                 <th>item name</th>                 <th>rate</th>                 <th>weight</th>                 <th>total</th>                               </tr>         </thead>         <tbody>             <tr ng-repeat="x in sales_items_detail">                 <td>{{ x.date }}</td>                 <td>{{ x.name }}</td>                 <td>{{ x.item_name }}</td>                 <td>{{ x.price }}</td>                 <td>{{ x.quantity }}</td>                 <td>{{ x.price*x.quantity }}</td>             </tr>         </tbody>         <tfoot>             <tr>                 <td colspan="4"><strong>total</strong></td>                 <td><strong>{{amount_sale = saletotal(sales_items_detail)}}</strong></td>               </tr>                                     </tfoot>     </table>                         </div> </div> <h3>naqdi roakker jama</h3> <div class="card-content table-responsive">     <table class="table table-bordered pagin-table">         <thead>             <tr>                 <th>date</th>                 <th>name</th>                 <th>detail</th>                 <th>amount</th>                               </tr>         </thead>         <tbody>             <tr ng-repeat="x in transection_detail_jama">                 <td>{{ x.date }}</td>                 <td>{{ x.name }}</td>                 <td>{{ x.detail }}</td>                 <td>{{ x.amount }}</td>             </tr>         </tbody>         <tfoot>             <tr>                 <td colspan="2"><strong>total</strong></td>                 <td><strong>{{amount_jama = amounttotal(transection_detail_jama)}}</strong></td>               </tr>                       </tfoot>     </table>                         </div> <h3>naqdi roakker naam</h3> <div class="card-content table-responsive">     <table class="table table-bordered pagin-table">         <thead>             <tr>                 <th>date</th>                 <th>name</th>                 <th>detail</th>                 <th>amount</th>                               </tr>         </thead>         <tbody>             <tr ng-repeat="x in transection_detail_naam">                 <td>{{ x.date }}</td>                 <td>{{ x.name }}</td>                 <td>{{ x.detail }}</td>                 <td>{{ x.amount }}</td>             </tr>         </tbody>         <tfoot>             <tr>                 <td colspan="2"><strong>total</strong></td>                 <td><strong>{{ amount_naam = amounttotal(transection_detail_naam)}}</strong></td>               </tr>                     </tfoot>     </table>                         </div> total = {{(parsefloat(amount_sale) + parsefloat(amount_naam)) - (parsefloat(amount_jama)) }} 

if remove if condition works if condition not working , shows nan. think here problem same variable name amount_sale. please me if can. in advance.

angularjs not assign value variable directly show returned through amounttotal(sales_items_detail) function

{{amount_sale = amounttotal(sales_items_detail)}} 

you should add code logic in controller , use resulted variable in double brackets see example

<!doctype html>  <html>  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>  <body>    <div ng-app="myapp" ng-controller="myctrl">      <div ng-if="obj">{{val = "wow"}}</div>  <div ng-if="obj">{{val = "how"}}</div>  <div>{{val}}</div>      </div>    <script>  var app = angular.module('myapp', []);  app.controller('myctrl', function($scope) {        $scope.obj = true;      $scope.val ="ok";  });  </script>    </body>  </html>


Comments

Popular posts from this blog

javascript - Create a stacked percentage column -

Optimising Firebase database by automatically overwriting data -

javascript - Angular UI-Grid customTemplate directive causing rows to load slowly/? -