Skip to content

Instantly share code, notes, and snippets.

@simonewebdesign
Last active August 29, 2015 14:20
Show Gist options
  • Save simonewebdesign/89d10b436e19b5a7fa34 to your computer and use it in GitHub Desktop.
Save simonewebdesign/89d10b436e19b5a7fa34 to your computer and use it in GitHub Desktop.
Fetching a RESTful resource in AngularJS (CoffeeScript)
%div{'ng-controller' => 'FooCtrl as foo'}
this is the content
%button{'ng-click' => 'foo.bar()'} Call bar()
%div{'ng-repeat' => 'report in foo.reports'}
this is one report: {{ report.reference }} {{ report.bar }}
class FooCtrl
constructor: (Report) ->
console.log "constructor called"
@reports = Report.query {}, ->
console.log "data fetched"
console.log "reports is", @reports
# @reports = [
# foo: 1
# bar: '123'
# ]
bar: ->
console.log "bar called"
@reports = [
foo: "baddaslkjasdjkladsjklads"
bar: 'fggdfdgf'
]
reportFactory = ($resource) ->
$resource '/contact_centre/index.json'
angular
.module('mmm.foo', [])
.factory('Report', ['$resource', reportFactory])
.controller('FooCtrl', ['Report', FooCtrl])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment