简体   繁体   English

插值/装订中的角度,数学函数

[英]Angular, math function in interpolation / binding

I am working with Angular and I am trying to do this 我正在与Angular合作,并且正在尝试这样做

<td>{{(obj.revenue.total / obj.clicks.total).toFixed(2)}}</td>

and in the table the result is something like this 在表中结果是这样的

**EPC** 0.60 NaN // returns this, why ?

I prepared a JSFiddle where you will see this 我准备了一个JSFiddle,您将在这里看到

<table>
  <tr>
    <th ng-repeat='header in headers'>{{header}}</th>
  </tr>
  <tr ng-repeat='obj in data'>
    <td></td>
    <td>{{obj.clicks.total.toFixed(2)}}</td>
    <td>{{obj.landing_pages.total_clicks.toFixed(2)}}</td>
    <td>{{obj.landing_pages.click_through_rate.toFixed(2)}}</td>
    <td>{{obj.conversions.total.toFixed(2)}}</td>
    <td>{{(obj.conversions.total / obj.landing_pages.total_clicks)}}</td>
    <td>{{obj.conversions.amount.toFixed(2)}}</td>
    <td>{{obj.cost.total.toFixed(2)}}</td>
    <td>{{(ob.conversions.amount - obj.cost.total).toFixed(2)}}</td>
    <td>{{obj.net.roi.toFixed(2)}}</td>
    <td>{{obj.cost.cpc}}</td>
    <td>{{(obj.revenue.total / obj.clicks.total).toFixed(2)}}</td>
    <td>{{obj.cost.ecpc.toFixed(2)}}</td>
  </tr>
</table>

and the controller 和控制器

.controller('PeopleCtrl', function($scope) {
  $scope.headers = [
    'Traffic Source',
    'Clicks',
    'LP Clicks',
    'LP CTR',
    'Conv',
    'CVR',
    'Rev',
    'Spend',
    'Profit',
    'ROI',
    'CPC',
    'EPC',
    'EPA'
  ];

  $scope.data = [];

  $scope.LoadMyJson = function() {
    angular.forEach(myJson, function(items) {
      $scope.data.push(items)
    })        
  };
  $scope.LoadMyJson();

})

http://jsfiddle.net/x5hfwdfs/ http://jsfiddle.net/x5hfwdfs/

see the td s CVR, Profit and EPC, are the ones where I need to calculate. 请参阅td的CVR,Profit和EPC,这些都是我需要计算的。

Do you guys have an idea of the issue ? 你们对这个问题有想法吗?

You can use the fractionSize filter: 您可以使用fractionSize过滤器:

<td>{{obj.clicks.total | fractionSize: 2}}</td>

You can see the example here: 您可以在此处查看示例:

https://docs.angularjs.org/api/ng/filter/number https://docs.angularjs.org/api/ng/filter/number

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM