私は最近angularjsを使い始めました。しかし、モジュールの概念は私を混乱させます。
angular チュートリアルの 1 つに、次のコードがあります。
'use strict';
/* Services */
var phonecatServices = angular.module('phonecatServices', ['ngResource']);
//this line's added by me
phonecatServices.constant('SomeConstant', 123);
phonecatServices.factory('Phone', ['$resource',
function($resource){
return $resource('phones/:phoneId.json', {}, {
query: {method:'GET', params:{phoneId:'phones'}, isArray:true}
});
}]);
angularjs は、はるかにクリーンな nodejs と同様の方法でモジュールを定義できるのに、constant や factory などのヘルパー関数を必要とするのはなぜですか? このアプローチにはどのような利点があるのか 混乱しています。
var $resource = require('$resource');
var SomeConstant = 123;
var Phone = $resource('phones/:phoneId.json', {}, {
query: {method:'GET', params:{phoneId:'phones'}, isArray:true}
});
};
exports.SomeConstant = SomeConstant;
exports.Phone = Phone;