javascript - AngularJS Promise Response Undefined -


i've read multiple articles on using $promise in angularjs , still can't figure out why i'm getting error code below:

controller code:

eventsapp.controller('eventcontroller',     function eventcontroller($scope, eventdata) {         $scope.sortorder = 'name';         eventdata.getevent().$promise.then(successongetevent(event), errorongetevent(response));          function successongetevent(event) {             $scope.event = event;             console.log(event);         };          function errorongetevent(response) {             console.log(response)         };     }); 

service code:

eventsapp.factory('eventdata', function($resource) {     return {         getevent: function() {             return $resource('/data/event/:id', {id:'@id'}).get({id:1});         }     } }); 

in chrome console window, error:

referenceerror: response not defined

any appreciated.

thank you.

in line...

eventdata.getevent().$promise.then(successongetevent(event), errorongetevent(response)); 

successongetevent , errorongetevent being executed right away. error because response (and event) aren't declared in context. try passing functions instead...

eventdata.getevent().$promise.then(successongetevent, errorongetevent); 

Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -