Skip to content

Instantly share code, notes, and snippets.

@awilson28
Last active December 8, 2015 17:51
Show Gist options
  • Save awilson28/cce98cbccbacb4b199c6 to your computer and use it in GitHub Desktop.
Save awilson28/cce98cbccbacb4b199c6 to your computer and use it in GitHub Desktop.
app.factory('AlbumFactory', function(DS, $state){
// defining a Js-Data resource
var AlbumFactory = DS.defineResource({
basePath: 'api', // what string prepends each uri ?
name: 'albums', // basePath + name = endpoint ('api/albums')
idAttribute: '_id', // where on the object is the primary key stored?
methods: {
go: function(){
// transition to songs state
$state.go('songs', {_id: this._id})
}
}
})
return AlbumFactory;
})
.controller('AlbumController', function(AlbumFactory){
// GET to 'api/albums'
AlbumFactory.findAll()
.then(function(albums){
var firstAlbum = albums[0]
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment