You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Jonathan Casarrubias edited this page May 17, 2017
·
3 revisions
Extending Models
One of the new great features of the LoopBack SDK Builder it that allows you to extend models in order to add new functionality within models.
In order to avoid working directly on models and lose information when re-generating the sdk, you will need to create a new extended folder within shared at the same level of sdk and create a model.extended.ts file:
And then I implemented in the component as follows:
import{Model,ModelApi,ModelExtended,LoopBackConfig}from'./shared';
...
constructor(privatemodelApi: ModelApi){LoopBackConfig.setBaseURL('http://localhost:3000');LoopBackConfig.setApiVersion('api');modelApi.create({name: 'My Model',description: 'This is my super description'}).map((model: Model)=>newModelExtended(model)).subscribe((modelExtended: ModelExtended)=>{console.log(modelExtended.customFunction());});}