你也可以用通常的方式通过
主题
或
行为主体
服务:
public $btnSubject = new BehaviorSubject<boolean>();
现在,无论何时需要将false改为true,反之亦然,只要
next(//true or false)
:
return (errors) => errors.scan((retryAttempts, error) => {
if ( retryAttempts < maxRetry ) {
this.$btnSubject.next(true)
}
在组件中订阅该主题:
ngOnInit() {
this.mainService.$btnSubject.subscribe(val => this.isBtnDisabled = val)
}
p、 通常最好将Subject保持为类作用域私有,并创建另一个实例-
public btnSubject$ = this.$btnSubject.asObservable()
并订阅它。
旧帖子:
当你经过时
this.isBtnDisabled
到
retryWhen()
只需传递它的值,而不是对象的引用。
我不知道你想定在什么时候
isBtnDisabled
这是真的,所以也许有更好的方法,但我认为这也是可以的-你可以简单地引用它
ISBTN禁用
:
.subscribe(
res => {this.triggerBtn = this.mainService.triggerBtn }