Last active
December 8, 2015 17:39
-
-
Save awilson28/021f9afb2b47226d41e9 to your computer and use it in GitHub Desktop.
This file contains 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
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