Adding Custom Methods to Models

Create custom methods for your models using Restangular.extendModel(). This is an alias for:

  Restangular.addElementTransformer(route, false, fn);

Back to top

Example:

  Restangular.extendModel('accounts', function(model) {
    model.prettifyAmount = function() {};
    return model;
  });

  var accountPromise = Restangular.one('accounts', 1).get();

  accountPromise.then(function(account) {
    account.prettifyAmount(); // invoke your custom model method
  });

Back to top