Skip to content

Instantly share code, notes, and snippets.

@rubyonrailstutor
Created February 4, 2014 19:49

Revisions

  1. rubyonrailstutor created this gist Feb 4, 2014.
    23 changes: 23 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    # 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