Custom repository service for Angular9+, for easy work with the REST backend, with switch on fly from REST backend to the MOCK backend with save and use all CRUD operations
Installation
npm i --save ngx-repository
Links
Demo - Demo application with ngx-repository.
Stackblitz - Simply sample of usage on https://stackblitz.com
Usage
app.module.ts
;; @ {}
user-model.ts
;;; implements IModel @ id: number; @ username: string; password: string; { ; }
users-grid.component.ts
;;;; @ implements OnInit public editedUser: UserModel; public repository: Repository<UserModel>; public items$: Observable<UserModel> private mockedItems = 'username': 'user1' 'password': 'password1' 'id': 1 'username': 'user2' 'password': 'password2' 'id': 2 'username': 'user3' 'password': 'password3' 'id': 3 'username': 'user4' 'password': 'password4' 'id': 4 ; { thisrepository = thisdynamicRepositoryfork<UserModel>UserModel; } { thisrepository; /* For real backend this.repository.useRest({ apiUrl: environment.apiUrl, paginationMeta: { perPage: 2 } });*/ thisitems$ = thisrepositoryitems$; } { thiseditedUser = thisrepository; } { thiseditedUser = undefined; } { thisrepository; thiseditedUser = undefined; } { thisrepository; } { thisrepository; }
app.component.ts
......
License
MIT