1

I am showing an array which contains JSON and am directly showing this with HTML, here you can find elem.fc + elem.cpc. It's giving NaN as an output.

Here is my HTML:

<tr ng-show="table.table1loaded" ng-repeat="elem in filteredcampaignslist" ng-init="initializepopover()">
<td ng-show="app.ostype=='iOS'"><div class="text-center">{{elem.fc+elem.cpc}}</div></td>
</tr>
Amit Shakya
  • 748
  • 3
  • 8
  • 25

3 Answers3

5

Change {{elem.fc+elem.cpc}} to {{+elem.fc + +elem.cpc}} That should do the trick.

theharls
  • 163
  • 7
  • No this trick is not working, I need to subtract values some pleases, but this dosen't works in addition too. – Amit Shakya May 06 '16 at 07:37
  • If it's not working, that can only mean that elem.fc or elem.cpc are not numbers or strings representing numbers. Over to you to figure out why. – theharls May 06 '16 at 09:39
5

Please check this: How to parseInt in Angular.js

According to the Angular docs within that post, you cannot, as of the moment, perform such operations within expressions.

The best way to go around this is to create a function that does so within a controller and then bind it to your HTML.

HTML:

 <tr ng-show="table.table1loaded" ng-repeat="elem in filteredcampaignslist" ng-init="initializepopover()">
<td ng-show="app.ostype=='iOS'"><div class="text-center">{{ Total() }}</div></td>
</tr>

Inside AngularJS Controller:

$scope.Total = function() { return parseInt(elem.fc) + parseInt(elem.cpc); };
Community
  • 1
  • 1
1

This is the answer for versions 2 and above of angular:

Number('1234') // 1234
Number('9BX9') // NaN
trees_are_great
  • 3,583
  • 3
  • 25
  • 54