This is what I have:
ngOnInit() {
this._addServ.getDefaultAddress().subscribe((res)=>{
if(res.status){
//I need these next two functions to finish their async API requests
//before selectNormalDelivery is called
this.selectShippingAddress();
this.selectBillingAddress();
this.selectNormalDelivery();
}
})
}
I need selectShippingAddress
and selectBillingAddress
to finish their calls, and then for selectNormalDelivery
to be called. How can I accomplish this? I don't want to convert them into promises as they're called other times without needing to be chained. Is this something involving .then
?
This is the code for the functions:
selectShippingAddress(){
this.addressService.setShippingAddresses(this.cartService.shippingAddress.address_id).subscribe((res) => {
console.log('Set shipping address!')
console.log(res);
}, err => {
console.log('Failed to set shipping address')
console.log(err);
})
}
selectBillingAddress(){
this.addressService.setPaymentAddresses(this.cartService.billingAddress.address_id).subscribe((res) => {
console.log('Set billing address!')
console.log(res);
}, err => {
console.log('Failed to set billing address')
console.log(err);
})
}
If I try a .then
, I get the error Property 'then' does not exist on type 'void'.
, which makes sense as I'm not trying to return anything, I just need them to complete their calls for the API's sake.
Suggestions?