Checkout this answer to understand the approach. I am using to the same solution to implement the master guard as I have multiple guards and want to execute them in sequence.
In Master Guard -
return guard.canActivate(this.route, this.state);
The whole function is Specified below:
//Create an instance of the guard and fire canActivate method returning a promise
private activateGuard(guardKey: string): Promise<boolean> {
let guard: Guard1 | Guard2 | Guard3 | Guard4;
switch (guardKey) {
case GUARDS.GUARD1:
guard = new Guard1();
break;
case GUARDS.GUARD2:
guard = new Guard2();
break;
case GUARDS.GUARD3:
guard = new Guard3();
break;
case GUARDS.GUARD4:
guard = new Guard4(this._Guard4DependencyService);
break;
default:
break;
}
return guard.canActivate(this.route, this.state);
}
I am getting the error mentioned below:
Type 'boolean | Observable<boolean>' is not assignable to type 'boolean'.
Type 'Observable<boolean>' is not assignable to type 'boolean'.
Please find stackblitz link for the same
Screenshot shared below:
Please share your solution to get rid of this error.
Any help is appreciated thanks in advance!