1
angularjs錯誤我使用的資源向服務器一個電話,當我去的對服務器的回調
/viewEvent
基本URL,它工作正常。我收到所有的數據庫條目。然而,當我去
/viewEvent/1234
,其中1234是EVENTID
我得到一個不確定是不是函數這是從內部的角度崩潰。堆棧跟蹤是
TypeError: undefined is not a function
at copy (http://localhost:8000/js/lib/angular/angular.js:593:21)
at http://localhost:8000/js/lib/angular/angular-resource.js:410:19
at wrappedCallback (http://localhost:8000/js/lib/angular/angular.js:6846:59)
at http://localhost:8000/js/lib/angular/angular.js:6883:26
at Object.Scope.$eval (http://localhost:8000/js/lib/angular/angular.js:8057:28)
at Object.Scope.$digest (http://localhost:8000/js/lib/angular/angular.js:7922:25)
at Object.Scope.$apply (http://localhost:8000/js/lib/angular/angular.js:8143:24)
at done (http://localhost:8000/js/lib/angular/angular.js:9170:20)
at completeRequest (http://localhost:8000/js/lib/angular/angular.js:9333:7)
at XMLHttpRequest.xhr.onreadystatechange (http://localhost:8000/js/lib/angular/angular.js:9303:11) angular.js:575
當我檢查服務器時,請求是正確的。我可以看到它得到了1234,並從mongo數據庫中提取了正確的條目。
這是控制器邏輯
.controller("viewEventsController", ["$scope", 'EventService', '$location', function($scope, EventService, $location){
var path = $location.path().split('/');
var pathSize = path.length;
$scope.events = [];
if(pathSize === 2){
console.log("No event ID");
$scope.events = EventService.query();
}
else{
console.log("Event ID specified");
EventService.get({"eventID": path[pathSize - 1]}, function(data){
//$scope.events.push(data);
console.log(data);
}, function(error){
console.log(error);
});
}
}]);
和業務邏輯
service.factory('EventService', function($resource){
return $resource('api/viewEvent/:eventID');
});
它永遠不會讓回給控制器,所以我「有信心」這並不是說。 (看它是)
看看這個答案正確使用傳遞參數到$資源(eventID)。 http://stackoverflow.com/questions/19365714/how-to-pass-in-parameters-when-use-resource-service –