Angular 1.3を使うと現時点でDeveloper Guideをそのまま写経すると次のようなエラーが出ます。
AngularJSのDeveloper GuideのConceptual OverviewのAdding UI logic: Controllersをそのまま写経したら
Uncaught SyntaxError: Unexpected token .
と
Uncaught Error: [$injector:modulerr] http://errors.angularjs.org/1.3.7/$injector/modulerr?p0=invoice1&p1=Error%3…Flocalhost%3A8000%2Fbower_components%2Fangular%2Fangular.min.js%3A17%3A350)
のエラーが出てはまってたんですが、調べてみると解決しました。
AngularJS 1.3からはグローバルなコントローラーは認めない
angular.module('invoice1', [])
.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!");
};
});
これを下記のように書き換えてあげるとちゃんと動きます。(最初の2行)
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!");
};
});
Developer Guideでちゃんと1.3.8の分を見てるのにこれなので初心者にはいきなりの障壁でしたorz