Last active
August 29, 2015 14:20
-
-
Save simonewebdesign/89d10b436e19b5a7fa34 to your computer and use it in GitHub Desktop.
Fetching a RESTful resource in AngularJS (CoffeeScript)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%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 }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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