我正在查看 angularjs 示例,我发现了这个示例:
// This is a module for cloud persistance in mongolab - https://mongolab.com
angular.module('mongolab', ['ngResource']).
factory('Project', function($resource) {
var Project = $resource('https://api.mongolab.com/api/1/databases' +
'/angularjs/collections/projects/:id',
{ apiKey: '4f847ad3e4b08a2eed5f3b54' }, {
update: { method: 'PUT' }
}
);
Project.prototype.update = function(cb) {
return Project.update({id: this._id.$oid},
angular.extend({}, this, {_id:undefined}), cb);
};
Project.prototype.destroy = function(cb) {
return Project.remove({id: this._id.$oid}, cb);
};
return Project;
});
我不想使用魔术字符串静态资源,例如https://api.mongolab.com/api/1/databases/angularjs/collections/projects/:id
,而是希望在服务器上定义它,然后传递到模块中。我的问题是,你如何参数化模块,即如何从外部将 javascript 变量传递到模块中?