这个咖啡脚本代码试图创建一个精确的提供程序,但是我得到了这样的消息:提供者'ItemsProvider‘必须定义$get工厂方法。
我已经设置了$get方法。知道发生了什么吗?
'use strict'
app = angular.module('logica-erp')
app.provider 'ItemsProvider', [ ->
this.$get = ->
return {
}
]它无法加载以下消息:
Error: [$injector:modulerr] Failed to instantiate module logica-erp due to:
[$injector:pget] Provider 'ItemsProvider' must define $get factory method.编辑:这是生成的javascript:
(function() {
'use strict';
var app;
app = angular.module('logica-erp');
app.provider('ItemsProvider', [
function() {
return this.$get = function() {
return {};
};
}
]);
}).call(this);发布于 2016-06-30 19:54:56
CoffeeScript引入了语法糖衣,读者和老手都可能不太理解。将其编译到JS以查看发生了什么,这总是一个好主意。在我的实践中,隐性回报似乎是最大的麻烦制造者。
在本例中,CS代码编译为
app.provider('ItemsProvider', [
function() {
return this.$get = function() {
return {};
};
}
]);在这里,提供程序构造函数返回this.$get (函数)的值,而不是this对象。构造函数不应该返回任何内容(除了应该返回的罕见情况外):
app.provider('ItemsProvider', [
function() {
this.$get = function() {
return {};
};
}
]);小心箭头。
https://stackoverflow.com/questions/38130968
复制相似问题