2014-12-22 32 views
1

我創建了一個工廠來定義名爲theorder的資源。

當我打電話theorder(在orderFunctions.js)的新實例,我得到的錯誤:類型錯誤:未定義是不是一個函數

我一直兜兜轉轉試圖找出我我錯過了。

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"); 

     }); 

    }; 

}); 

回答

1

可變CON維持資源的新實例與資源命名相同。我是個白癡。

var ARGHHH = new theorder(newData); 
+0

替換

var theorder = new theorder(newData); 

'我是一個idiot.' +1 – Dinei