[restangular] extendModel and extendCollection belongs to IProvider (#25257)

* [restangular] extendModel and extendCollection belongs to IProvider

* fix(restangular): function returns the object
This commit is contained in:
Cyril Gandon
2018-04-30 18:16:06 +02:00
committed by Andy
parent 7c9875bc02
commit 16bffafcfc
2 changed files with 12 additions and 2 deletions

View File

@@ -69,6 +69,8 @@ declare namespace restangular {
setSelfLinkAbsoluteUrl(value: boolean): IProvider;
setParentless(value: any): IProvider;
setPlainByDefault(isPlain: boolean): IProvider;
extendModel(route: string, extender: (model: IElement) => any): IProvider;
extendCollection(route: string, extender: (collection: ICollection) => any): IProvider;
}
interface ICustom {
@@ -94,8 +96,6 @@ declare namespace restangular {
restangularizeCollection(parent: any, element: any, route: string): ICollection;
service(route: string, parent?: any): IScopedService;
stripRestangular(element: any): any;
extendModel(route: string, extender: (model: IElement) => any): void;
extendCollection(route: string, extender: (collection: ICollection) => any): void;
}
interface IScopedService extends IService {

View File

@@ -27,6 +27,16 @@ myApp.config((RestangularProvider: restangular.IProvider) => {
return elem;
});
RestangularProvider.extendModel('accounts', function(model: any) {
model.prettifyAmount = function() {};
return model;
});
RestangularProvider.extendCollection('accounts', function(collection: any) {
collection.totalAmount = function() {};
return collection;
});
RestangularProvider.setRestangularFields({
id: "_id",
route: "restangularRoute",