Skip to content

Latest commit

 

History

History
24 lines (17 loc) · 1.86 KB

README.md

File metadata and controls

24 lines (17 loc) · 1.86 KB

Model pattern for Angular by @tomastrajan Build Status

Getting started

  1. Create model.service.ts with following content.
  2. Import and provide MODEL_PROVIDER (from model.service.ts) constant in your CoreModule (use AppModule in case you don't have CoreModule)
  3. Use model in your own services. Import ModelFactory and inject it in service's constructor, then create model instance with this.model = this.modeFactory.create(initialData). Expose model with descriptively named variable (eg: this.todos$ = this.model.data$)
  4. Use service in your component. Import and inject service into components constructor. Subscribe to services data in template todosService.todos$ | async or explicitly this.todosService.todos$.subscribe(todos => { /* ... */ })

Examples

Built with Angular CLI