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>

3 Answers 3

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); };
Sign up to request clarification or add additional context in comments.

Comments

5

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

2 Comments

No this trick is not working, I need to subtract values some pleases, but this dosen't works in addition too.
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.
1

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

Number('1234') // 1234
Number('9BX9') // NaN

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.