Skip to content

Instantly share code, notes, and snippets.

@awilson28
Last active December 8, 2015 17:39
Show Gist options
  • Save awilson28/021f9afb2b47226d41e9 to your computer and use it in GitHub Desktop.
Save awilson28/021f9afb2b47226d41e9 to your computer and use it in GitHub Desktop.
app.factory('AlbumFactory', function(DS){
var AlbumFactory = DS.defineResource({
basePath: 'api',
name: 'albums',
idAttribute: '_id',
// like the mongoose methods object,
//this object allows us to add
// functionality to the prototype
// i.e. create instance methods
methods: {
raw: function(){
return 'api/albums/'+ this._id + '.image'
}
}
})
return AlbumFactory;
})
.controller('AlbumController', function(AlbumFactory){
AlbumFactory.find('435')
.then(function(album){
// rawUrl = 'api/albums/435.image'
var rawUrl = album.raw();
// change the album
album.name = 'newName';
// save the changes to DB
return album.DSUpdate();
})
.then(function(updated){
updated.name = 'newName'
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment