I have a PollDetailResolve class that resolves a poll before being navigating to the poll-detail page. However, I also need to resolve a separate piece of data (a boolean that we'll call canVote
) that will also make use of PollService.
What is the best way to resolve two or more pieces of data?
@Injectable()
export class PollDetailResolve implements Resolve<Poll> {
constructor(private pollService: PollService, private router: Router) { }
resolve(route: ActivatedRouteSnapshot): Observable<Poll> | boolean {
let id = route.params['id'];
return this.pollService.getById(id)
.map(poll => {
if (poll) {
return poll;
} else {
console.log("NOT FOUND!"); // TODO reroute
}
},
err => {
console.error(err);
});
}
}
My poll-detail ngOnInit() function:
ngOnInit(): void {
this.route.data.forEach((data: { poll: Poll }) => {
this.poll = data.poll;
this.sharePoll(this.poll);
});
}