Skip to content

Model pattern for Angular (2, 4, ...), manage and share your state with simple services using RxJS Subjects and Observables

Notifications You must be signed in to change notification settings

danww/angular-model-pattern-example

 
 

Repository files navigation

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

About

Model pattern for Angular (2, 4, ...), manage and share your state with simple services using RxJS Subjects and Observables

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 52.8%
  • HTML 35.3%
  • CSS 7.3%
  • JavaScript 3.2%
  • Shell 1.4%