我在我的模板中为所有商店选择值使用异步管道,因为它自己完成所有清理工作,包括取消订阅。
但是当我手动订阅我的 auth gaurd 中的值时,我需要取消订阅吗?如果是,那么最好的方法是什么?
@Injectable()
export class AuthGaurd implements CanActivate{
constructor(
private store: Store<fromRoot.State>,
private router: Router
){}
canActivate(){
this.store.select(getLoggedInState).subscribe(res => {
if(res){
return true
}else {
this.router.navigate(['/login']);
}
});
return false;
}
}