【发布时间】:2013-04-28 23:49:48
【问题描述】:
我正在查看 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 变量从外部传递到模块中?
【问题讨论】:
-
也许这个可以激励你这样做stackoverflow.com/questions/16339595/…
-
我会尝试在视图文件中定义我的配置模块,谢谢
-
我不知道我是否理解正确你在找什么,但我认为你需要使用提供者而不是工厂docs.angularjs.org/guide/providers#provider-recipe
标签: angularjs