Skip to content

Instantly share code, notes, and snippets.

@rubyonrailstutor
Created February 4, 2014 19:49
Show Gist options
  • Save rubyonrailstutor/8810975 to your computer and use it in GitHub Desktop.
Save rubyonrailstutor/8810975 to your computer and use it in GitHub Desktop.
promises
# the controller
angular.module('Lunch.controllers', [])
.controller('LunchCtrl', ($scope, LunchMates) ->
# angular no longer 'unwraps' promises
LunchMates.getLunchMates().then (data) ->
$scope.lunchers = data
)
# the service
angular.module('Lunch.services', [])
.factory 'LunchMates', ($rootScope, $q, $http) ->
LunchMates =
getLunchMates: () ->
d = $q.defer();
$http.get('/lunchers').then (response, status) ->
d.resolve(response.data)
return d.promise
return LunchMates
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment