我创建了一个工厂来定义名为theorder的资源。
当我调用order的新实例时(在orderFunctions.js中)我得到错误: TypeError:undefined不是函数
我一直在试图找出我失踪的东西。
order.js
angular.module('app').factory('theorder', function($resource) {
var OrderResource = $resource('/api/users/:id', {_id: "@id"}, {
update: {method:'PUT', isArray:false}
});
return OrderResource;
});
orderFunctions.js
angular.module('app').factory('orderFunctions', function($http, theorder) {
return {
createOrder: function(newData) {
console.log("this is from orderFunctions " + JSON.stringify(newData, null, 4));
var theorder = new theorder(newData);
}
}
});
orderCtrl.js
angular.module('app').controller('requirementsCtrl', function($scope, $http, $location, theorder, orderFunctions, $q) {
$scope.step2 = function() {
var requirements = {
site: $scope.site,
speedySpruce: $scope.speedySpruce,
superSpruce: $scope.superSpruce
}
$http.get('/api/theSession').
success(function(data, status, headers, config) {
var currentData = data;
var clone = angular.copy(requirements);
var newData = angular.extend(clone, currentData);
orderFunctions.createOrder(newData).then(function() {
console.log("success");
}, function() {
console.log("fail");
})
}).
error(function(data, status, headers, config) {
console.log("another error");
});
};
});
答案 0 :(得分:1)
包含新资源实例的变量的名称与资源相同。我是个白痴。
代替
var theorder = new theorder(newData);
与
var ARGHHH = new theorder(newData);