Skip to content

Instantly share code, notes, and snippets.

@arturovt
Created June 6, 2019 23:22
Show Gist options
  • Save arturovt/eba598fd3ec4ef0d300e0defc70637c2 to your computer and use it in GitHub Desktop.
Save arturovt/eba598fd3ec4ef0d300e0defc70637c2 to your computer and use it in GitHub Desktop.
@Injectable()
export class TodosResolver implements Resolve<Todo[]> {
private todos: Todo[] = [];
constructor(private todoService: TodoService) {}
public resolve(): Todo[] | Observable<Todo[]> {
if (this.todos.length) {
return this.todos;
}
return this.todoService.getTodos().pipe(
tap((todos) => {
this.todos = todos;
})
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment