Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en-US">
- <!--
- Belajar Angular JS dengan praktek 3
- invoice dan currency
- tema: filter
- Yoesoff / Yusuf
- blog : undebugable.wordpress.com
- penjelasan : Belajar praktek angularJS
- -->
- <head>
- <!-- Load Angular -->
- <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
- </head>
- <body>
- <div ng-app="invoice1" ng-controller="InvoiceController as invoice">
- <b>Invoice:</b>
- <div>
- Quantity: <input type="number" min="0" ng-model="invoice.qty" required >
- </div>
- <div>
- Costs: <input type="number" min="0" ng-model="invoice.cost" required >
- <select ng-model="invoice.inCurr">
- <option ng-repeat="c in invoice.currencies">{{c}}</option>
- </select>
- </div>
- <div>
- <b>Total:</b>
- <span ng-repeat="c in invoice.currencies">
- {{invoice.total(c) | currency:c}}
- </span>
- <button class="btn" ng-click="invoice.pay()">Pay</button>
- </div>
- </div>
- </body>
- <script>
- var app = angular.module('invoice1', []);
- app.controller('InvoiceController', function() {
- this.qty = 1;
- this.cost = 2;
- this.inCurr = 'EUR';
- this.currencies = ['USD', 'EUR', 'CNY'];
- this.usdToForeignRates = {
- USD: 1,
- EUR: 0.74,
- CNY: 6.09
- };
- this.total = function total(outCurr) {
- return this.convertCurrency(this.qty * this.cost, this.inCurr, outCurr);
- };
- this.convertCurrency = function convertCurrency(amount, inCurr, outCurr) {
- return amount * this.usdToForeignRates[outCurr] / this.usdToForeignRates[inCurr];
- };
- this.pay = function pay() {
- window.alert("Thanks!");
- };
- });
- </script>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement