【发布时间】:2017-08-21 20:41:06
【问题描述】:
我在模板中为所有商店选择值使用异步管道,因为它自己完成所有清理工作,包括取消订阅。
但是当我手动订阅我的 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;
}
}
【问题讨论】:
-
你没有取消订阅,你想做什么?
-
@Aravind 我在哪里退订?退订线会去哪里?
-
你不应该订阅你的后卫,试试在 github 上发表评论。 github.com/ngrx/store/issues/270#issuecomment-260845982
-
@Adam 谢谢!!这太棒了!
-
这并不意味着您可以对帖子投反对票
标签: angular observable ngrx unsubscribe