如何在Angular js计算中删除NaN?

时间:2017-11-02 11:23:05

标签: angularjs

我有一个简单的计算逻辑,但是当我尝试计算时,它会显示NaN。请给我正确的解决方案空白显示那里

<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<body>

<p>Change the value of the input field:</p>

  <div ng-app="" ng-init="okpcs=10">
    <p>Qty for Bundle Packing :- <input type="number" ng-model="qty"></p>
    <h3> Bundles :- {{okpcs / qty}}</h3>
  </div>


</body>
</html>

1 个答案:

答案 0 :(得分:2)

你最初也需要一个qty值,否则它是一个空字符串并返回NAN

  <div ng-app="" ng-init="okpcs=10;qty=10">

<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<body>

<p>Change the value of the input field:</p>

  <div ng-app="" ng-init="okpcs=10;qty=10">
    <p>Qty for Bundle Packing :- <input type="number" ng-model="qty"></p>
    <h3> Bundles : {{okpcs / qty}}</h3>
  </div>


</body>
</html>