【发布时间】:2015-11-25 05:06:07
【问题描述】:
我正在尝试用coffeescript 编写一个好的angularjs。 但我收到了这个错误,甚至定义了“帖子”:
TypeError: Cannot read property 'post' of undefined
这里是代码:
'use strict'
class SupervisorEmployeeFactory
@$inject = ['$http', 'myConfig', '$auth']
constructor : (@$http, @myConfig, @$auth) ->
return {
getAllSupervisorEmployee: getAllSupervisorEmployee,
getActiveSupervisorEmployee: getActiveSupervisorEmployee,
getInactiveSupervisorEmployee: getInactiveSupervisorEmployee,
getAbsentSupervisorEmployee: getAbsentSupervisorEmployee
}
getAllSupervisorEmployee = ->
# Here is where the error happens in the 'post'. Probably in the other methods too.
@$http.post @myConfig.url + '/someurl/' + @$auth.getToken()
getActiveSupervisorEmployee = ->
@$http.post @myConfig.url + '/anotherUrl/' + @$auth.getToken()
getInactiveSupervisorEmployee = ->
@$http.post @myConfig.url + '/otherSomeUrl/' + @$auth.getToken()
getAbsentSupervisorEmployee = ->
@$http.post @myConfig.url + '/otherOtherUrl/' + @$auth.getToken()
angular
.module 'heinz.dashboard'
.factory 'SupervisorEmployeeFactory', SupervisorEmployeeFactory
这是生成的 javascript 代码:
(function() {
'use strict';
var SupervisorEmployeeFactory;
SupervisorEmployeeFactory = (function() {
var getAbsentSupervisorEmployee, getActiveSupervisorEmployee, getAllSupervisorEmployee, getInactiveSupervisorEmployee;
SupervisorEmployeeFactory.$inject = ['$http', 'myConfig', '$auth'];
function SupervisorEmployeeFactory($http, myConfig, $auth) {
this.$http = $http;
this.myConfig = myConfig;
this.$auth = $auth;
return {
getAllSupervisorEmployee: getAllSupervisorEmployee,
getActiveSupervisorEmployee: getActiveSupervisorEmployee,
getInactiveSupervisorEmployee: getInactiveSupervisorEmployee,
getAbsentSupervisorEmployee: getAbsentSupervisorEmployee
};
}
getAllSupervisorEmployee = function() {
return this.$http.post(this.myConfig.url + '/someUrl/' + this.$auth.getToken());
};
getActiveSupervisorEmployee = function() {
return this.$http.post(this.myConfig.url + '/anotherUrl/' + this.$auth.getToken());
};
getInactiveSupervisorEmployee = function() {
return this.$http.post(this.myConfig.url + '/otherSomeUrl/' + this.$auth.getToken());
};
getAbsentSupervisorEmployee = function() {
return this.$http.post(this.myConfig.url + '/otherOtherUrl/' + this.$auth.getToken());
};
return SupervisorEmployeeFactory;
})();
angular.module('heinz.dashboard').factory('SupervisorEmployeeFactory', SupervisorEmployeeFactory);
}).call(this);
你们能给我一些关于我做错了什么的想法吗?
【问题讨论】:
标签: javascript angularjs coffeescript