I had problems with $q.defer();
When I used callbacks , my code worked (the update was updated), but with $q.defer(); it is not .
This is my code:
Service:
eventsApp.factory('eventData', function($http, $q) { return { getEvent: function(callback) { var deferred = $q.defer(); $http({method: 'GET', url: '/node/nodejsserver/server.js'}). success(function(data, status, headers, config){
Controller:
eventsApp.controller('EventController', function EventController($scope, eventData) { $scope.event = eventData.getEvent(); } );
But that will not work.
Then I found this answer , and I updated my controller as follows:
eventsApp.controller('EventController', function EventController($scope, eventData) { eventData.getEvent().then(function(result) { $scope.event = result; }); } );
and it works.
What is the difference between non-working and working code?
source share