简体   繁体   中英

Loan Calculator

I'm new to Angular JS. I was trying to create a Loan Calculator with Angular JS and the prototype seems to work well.

I want to ask all Angular's guru, if there is a better way (using the framework) to write only a formula for both interest rate. Actually I'm doing this thanks to a function as follow:

function totalCalc(years, amount) {
    calc = (((amount * 9.9 * years) /1200)/12) + (amount / (years*12));
    $scope.total = currencyRround(calc);

    calc2 = (((amount * 12.5 * years) /1200)/12) + (amount / (years*12));
    $scope.total2 = currencyRround(calc2);
}

I was thinking to get this work with ng-repeat , defining interest's rates as follow:

$scope.interests= [
    {
        rate: '9.9'
    },{
        rate: '12.5'
    }
];

and then integrate the values in a forEach as follow:

angular.forEach($scope.interests, function(s){
    interest = s.rate;
}

but I haven't enough experience to think further... Do you find this could be a good way to get things done?

Here is the JSFiddle with the "Prototype": http://jsfiddle.net/645Xs/2/

Thank you for the help :)

 <div class="item">
            <h1>Rata mensile in CHF:</h1>
            <h2 ng-repeat='rate in [9.9,12.5]'>
                {{rate}} = {{(((one * rate * (two / 12)) /1200)/12) + (one / two) | number:2}}
            </h2>
        </div>

updated fiddle

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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