Created
June 6, 2019 23:22
-
-
Save arturovt/eba598fd3ec4ef0d300e0defc70637c2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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