I have an angular application that makes a request to an Http service and calls a switch on another Http service. For some reason, a request in switchMap only starts when the parent call is first called. Otherwise, the parent request is triggered, but switchMap is not, here is the code:
this._receivableService.newTenantDebitCredit(tenantCredit) .take(1) .switchMap(result => // Refresh the lease receivables before giving result this._receivableService.getAll({ refresh: true, where: { leaseId: this.leaseId } }).take(1).map(() => result) ) .subscribe( ... )
How can I make the getAll request on the switch card run every time the newTenantDebitCredit method is called on it?
Edit: here is the whole function called on click . when I press the button for the first time for this device, both methods are executed. If I try Unit, which already had a method called (without updating), only the first method is executed. I understand that a lot of this may not be entirely clear; this is a rather large project at the moment.
public submitTenantCredit() { this.isLoading = true; let tenantCredit: NewTenantDebitCreditData; let receivableDefinitions: ReceivableDefinition[] = []; // construct receivable defintions for NewTenantDebitData model receivableDefinitions = this._constructReceivableDefinitions(); // construct data we will be POSTing to server. tenantCredit = new NewTenantDebitCreditData({ siteId: this._apiConfig.siteId, leaseId: this.leaseId, isCredit: true, receivables: receivableDefinitions, reason: this.actionReason }); // make service call and handle response this._receivableService.newTenantDebitCredit(tenantCredit) .take(1) .switchMap(result => // Refresh the lease receivables before giving result this._receivableService.getAll({ refresh: true, where: { leaseId: this.leaseId } }).take(1).map(() => result) ) .take(1) .subscribe( (receivables) => { this.closeReasonModal(); let refreshLeaseId = this.leaseId; this.leaseId = refreshLeaseId; this.isLoading = false; this.refreshBool = !this.refreshBool; this._debitCreditService.refreshUnitInfo(); this._notifications.success(`The tenant credit for ${this.customerName} - Unit ${this.unitNumber} was submitted successfully`); }, (error) => { console.error(error); this.isLoading = false; } ) }
If this helps newTenantDebitCredit( ), this is an HTTP POST request, and getAll() is a GET request.
source share