I'm trying to disable/enable a button in a component based on property status false/true. This status changes in the service based on an if-statement.
*.service.ts:
public connectionRetry(
initialDelay,
maxRetry,
errorWhiteList,
triggerBtn,
) {
return (errors) => errors.scan((retryAttempts, error) => {
if ( retryAttempts < maxRetry ) {
triggerBtn = true;
}
if ( !errorWhiteList.includes(error.status ) || retryAttempts > maxRetry) {
triggerBtn = false;
throw error;
}
return retryAttempts + 1;
}, 0).switchMap((retryAttempts) => {
let delay = Math.pow(2, retryAttempts - 1) * initialDelay;
return Observable.timer(delay);
});
}
*.component.ts:
public isBtnDisabled = false;
constructor ( public mainService: MainService, public mainUtils: MainUtils ) {}
public storeData(paramX, paramY) {
this.mainService.addUser(paramX, paramY)
.retryWhen(
this.mainUtils.connectionRetry(
xxx,
xxx,
[xxx],
this.isBtnDisabled,
))
.subscribe(
res => {....},
error = > {...}
);
}
*.component.html:
<button [disabled]="!form.valid || isBtnDisabled">button text</button>
The issue is that I just can't make this concept working... the property isBtnDisabled keeps always the status: false in the component ts and html.
If I implement the function: connectionRetry() directly in the *.component.ts, it works straight forward, but not via the service. Has it to do with the angular digest cycle?
I have been searching (also here in SOF) and trying different approach as, but unfortunately without success. It seems to be simple actually.