Hi,
2. You can alter the restangular models/add new methods to them. You could, for example, add a method to getHref() which would create and return the href based on the object fields. You can also make this a property, instead of a method.
3. This depends on your app a bit but again, you could create a player.publish() method (where player is a restangular model).
4. I do return the refreshed object and just change the model fields in js.
The place to extend the models is in the .config() or .run() blocks of your app. Something like this:
.run(function(Restangular) {
// this adds a model.save() method to all models that does either create or update, depending on whether the model is new or not.
Restangular.setOnElemRestangularized(function(elem, isCollection) {
if (!isCollection) {
elem.save = function(opts) {
if (elem._id) {
return elem.put(opts);
} else {
return elem.post(undefined, undefined, opts); }
};
}
return elem;
});
// this adds player.getTitle() to all 'player' models (any other model will not get it).
Restangular.extendModel('players', function(player) {
player.getTitle = function() {
return player.title + ' ' + player.createdAt;
});
});
Cheers,
Dan