angular-repository
API Repository factory for Angular Js based on ngResource
Installation
Install with bower:
$ bower install angular-vrepository --save
Install with npm:
$ npm install angular-repository
Load the angular-repository
module in your app.
angular;
Configure
angular ; { var myConfig = url: 'http://api.com' //required config parameter { //optional global callback return response; } { //optional global callback example if this let data = responsedata; if data instanceof Array for var key in data if data datakey = datakey; return data; else return data; } ; RepositoryFactoryProvider; } /** * Check if property exist * * @param obj * @param paths * @returns */ { for var i = 0; i < pathslength; i++ if !obj || !obj return false; obj = objpathsi; return true; }
Usage Example
Example usage:
Create your entity class
//remeber that your mdoel class has to extend Entity class provider by this package { //this 2 lines are required !!! let entity = superparameters; if entityid return entity; thisid = parametersid; thisemail = parametersemail; thisname = parametersname; //after parameter remember to turn on watcher //so multiple API call will not reset your changes this; }
Example List controller for your model
static $inject = '$scope' 'RepositoryFactory'; thisrepository = this; { thisfactory = factory; this$scope = $scope; this$scope; this$scope; } { if newValue !== oldValue thisrepository; } { return thisfactory; }
You can also provide onSuccess
and onError
callback to the getRepository
method
//.... { return thisfactory; } { return response; } { return response; }
They will override global callback provided in your config for this specific model only.