Looking at Angular JS conceptual overview. Here - 'currencyConverter',
function(converter) <-- 'currencyConverter' is the factory's name, but
(converter) is it factory's scope, or is it the whole function itself? What
is this parameter?
angular.module('invoice2', ['finance2']).controller('InvoiceController',
['currencyConverter', function(converter)
{
this.qty = 1; this.cost = 2; this.inCurr = 'EUR'; this.currencies =
converter.currencies;
this.total = function total(outCurr)
{
return converter.convert(this.qty * this.cost, this.inCurr, outCurr);
};
}]);
angular.module('finance2', []).factory('currencyConverter', function()
{
var currencies = ['USD', 'EUR', 'CNY'];
var usdToForeignRates = {
USD: 1,
EUR: 0.74,
CNY: 6.09
};
var convert = function (amount, inCurr, outCurr) {
return amount * usdToForeignRates[outCurr] / usdToForeignRates[inCurr];
};
return {
currencies: currencies,
convert: convert
};
});
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.