专栏名称: 前端JavaScript
分享 | 学习 | 交流 | 原创 分享是学习的开始;学习不必要从头开始,是从现在开始;交流能沟通你我,提高你的学识;期待你的加入!!! web前端技术交流,JavaScript,HTML5,CSS3……
目录
相关文章推荐
51好读  ›  专栏  ›  前端JavaScript

Angular开发者指南(二)概念概述

前端JavaScript  · 公众号  · Javascript  · 2017-03-10 07:19

正文

请到「今天看啥」查看全文


添加UI逻辑:控制器


invoice1.js


angular.module('invoice1', [])

.controller('InvoiceController', function InvoiceController() {

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!');

};

});


index.html


Invoice:

Quantity:

Costs:







请到「今天看啥」查看全文