html - angularjs数学计算

标签 html angularjs ionic-framework

我正在开发一个贷款计算器,我在其中使用 ionic 范围 slider 来选择贷款金额、利率、贷款期限等。还有一个每月支付范围。当贷款金额、利率和期限发生变化时,这个每月还款范围应该这样计算。

(loanamount*interest rate)/loan duration

因此,当我们更改贷款金额、利率和贷款期限时,基本上每个月的还款范围应该会发生变化。我该怎么做?

到目前为止我的代码:

<content has-header="true">


    <div class="item item-divider">
     Select your Loan Amount : 
    </div>
    <div class="item range">
    <div id='slider'>
    <input type="range" name="number" min="100" max="1000000" step="100.00"  ng-model="loanAmount">
    <font color="#009ACD"><b>Loan Amount:</b></font> <input type="text" ng-model="loanAmount" min="100" max="1000000" />
    </div>
    </div>

     <div class="item item-divider">
     Select your Interest Rate: 
    </div>
    <div class="item range">
    <div id='slider'>
    <input type="range" name="volume" min="0" max="100" step="0.01"  ng-model="interestRate">
    <font color="#009ACD"><b>Interest Rate:</b></font> <input type="text" ng-model="interestRate" min="0" max="100" />
    </div>
    </div>

    <div class="item item-divider">
     Select your Loan Term : 
    </div>
    <div class="item range">
    <div id='slider'>
    <input type="range" name="volume" min="0" max="30"  ng-model="loanTerm">
    <font color="#009ACD"><b>Loan Term:</b></font> <input type="text" ng-model="loanTerm" min="0" max="30" />
    </div>
    </div>

    <div class="item item-divider">
     Your Monthly Payment : 
    </div>
    <div class="item range">
    <div id='slider'>
    <input type="range" name="volume" min="0" max="1000000"   ng-model="monthlyPayment">
    <font color="#009ACD"><b>Monthly Payment:</b></font> <input type="text" ng-model="monthlyPayment" min="0" max="1000000" />
    </div>
    </div>

    <center><button class="button button-positive" type="reset" ng-click="reset()">
     &nbsp;&nbsp;Reset&nbsp;&nbsp;&nbsp;
    </button></center>
</content>

我可以在 HTML 本身或 Controller 内部执行此操作吗?

最佳答案

你可以!!如果你想在 divspan 而不是输入元素中显示,你可以这样做 -

<div>{{ (loanAmount * interestRate) / loanDuration }}</div>

因为您不能在ng-model 中有表达式,您可以计算每个输入元素的ng-change 中的值。但我不会这样做,因为我需要重复代码。我宁愿在 Controller 中有一个函数来计算这个

$scope.calculateMonthyAmount = function() {
   $scope.monthlyPayment = Math.round(($scope.loanAmount * $scope.interestRate) / $scope.loanDuration * 100)/100; 
  // you can instead use $filter `number` for formatting
}

并监视范围变量以调用此函数,或在其他输入元素的 ng-change 上调用此函数。

关于html - angularjs数学计算,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26010136/

相关文章:

javascript - 从对象内的数组获取值,范围问题

ios - 如何在 index.html 中添加内容安全策略

html - 在模板网页上将 CSS 直接添加到 HTML 中

jquery - 允许弹出气泡到 jQuery UI 对话框的 "break out"

javascript - Fastclick.js 与 AngularJS 集成

javascript - 模型personalDeatail.add 值中的数据不会自动更新。我究竟做错了什么?

javascript - 错误错误 : Uncaught (in promise): TypeError: Cannot set property 'devices' of undefined in ionic 4 Angular

javascript - 引用页面上的特定位置

javascript - 如何使用 JavaScript 将 html 页面内容保存在 .txt 文件中?

javascript - 使用angularjs获取函数返回值