Skip to content

Instantly share code, notes, and snippets.

@tomastrajan
Created May 4, 2017 23:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomastrajan/94cc07d2ede0fbe18bed4e561b6c920d to your computer and use it in GitHub Desktop.
Save tomastrajan/94cc07d2ede0fbe18bed4e561b6c920d to your computer and use it in GitHub Desktop.
Angular Model Pattern - use model in service
@Injectable()
export class TodosService {
private model: Model<Todo[]>;
todos$: Observable<Todo[]>;
constructor(private modelFactory: ModelFactory<Todo[]>) {
this.model = this.modelFactory.create([]);
this.todos$ = this.model.data$;
}
}
export interface Todo {
name: string;
done: boolean;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment