ng-repeat返回0而不是NaN

时间:2016-01-26 08:59:42

标签: angularjs nan

在使用ng-repeat显示表格行时,我会即时计算其中一个值。如果计算的分母是0,我得到Nan(显然)。返回0而不是NaN的常用方法似乎无效。

这是我的观点HTML:

<tr ng-repeat="metricRow in tierData.metrics track by $index " ng-click="rowClick(metricRow)">
      <td ng-switch="key" ng-repeat="(key,val) in metricsHeaders " ng-if="val.exposed" ng-class="{'text-field': val.type == 'text'}">
        <div ng-switch-when="headline">
          <b>{{metricRow.headline}}</b><br/>
          {{metricRow.description_1}}<br/>
          {{metricRow.description_2}}<br/>
          <a href="{{metricRow.url}}" target="_blank">link</a>
        </div>
        <div ng-switch-when="click_through_rate">
          {{((metricRow.clicks/metricRow.impressions).toFixed(2) || 0) + "%"}} <!-- here's the problem -->
        </div>
        <div ng-switch-default>
          {{metricRow[key]}}
        </div>

      </td>
</tr>

0 个答案:

没有答案