0
我有一個頁面用於在我們寧靜的web服務中創建一個新的資源。頁面的控制器如下:
appController.controller('AddCtrl', ['$scope', 'Person',
function($scope, $location, Person) {
$scope.person = new Person();
$scope.emailList = [];
$scope.add = function() {
$scope.emailList.push({email: $scope.email});
$scope.person.emailList = $scope.emailList;
$scope.person.$save();
};
}]);
我的服務,人,看起來是這樣的:
appService.factory('Person', ['$resource',
function($resource, uuid){
return $resource(baseUrl + 'candidate/:uuid', {}, {
query: {method:'GET', isArray:true},
get: {method:'GET', params:{uuid: uuid}},
save: {method: 'POST'},
remove: {method: 'DELETE', params:{uuid: uuid}}
});
}
]);
然而,當我查看該頁面,我注意到在該行的錯誤:
$scope.person = new Person();
Person is not a function at new <anonymous> ...
我不知道爲什麼這是一個問題。之前它工作正常。我也嘗試添加一個方法創建的服務:
appService.factory('Person', ['$resource',
function($resource, uuid){
var r = $resource(baseUrl + 'candidate/:uuid', {}, {
...
});
r.create = function() {
return $resource(baseUrl + 'candidate', {});
}
return r;
}
]);
不過,我收到我的控制器以下錯誤:
$scope.person = Person.create();
TypeError: Cannot read property 'create' of undefined at new <anonymous>