Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to wait for the subscribe to finish before going back to caller method in angular

save(job: Model, status: string) {
    console.log('Starting apiService.serviceMethod');
    this.apiService.serviceMethod(job, status).pipe(
        switchMap((job: Model) => {
            if (job) {
                // Some update of job is require here since the GET call doesn't know 
                // whereas the UI does. 
                // Modify job variable here.
            
                console.log('Starting PUT call');
                return this.apiService.updatePutMethod(job); 
            } else {
                console.log('Skipping PUT call');
                return of(null);
            }
        })
    ).subscribe(() => {
        console.log("Ready to emit");
        this.notify.emit('Saved!');
    });
}


import { of } from 'rxjs';

serviceMethod(job: Model, status: string): Observable<Model> {
    if (status && (status === 'Publish' || status === 'UnPublish')) {
        console.log('Staring POST call');
        return this.firstPostMethod(task).pipe(
            switchMap((task) => {
                console.log('Starting GET call');               
                return this.firstGETCall(task);
            })
        );
    } else {
        // either status is null/empty or does not equal either of the strings.
        return of(null);
    }
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript string to ascii array 
Javascript :: amazon s3 upload error ssl certificate 
Javascript :: how can we access the data from array object in javascript 
Javascript :: javascript dom methods list 
Javascript :: solid in css 
Javascript :: Generate random phone numbers in POSTMAN 
Javascript :: use length to resize an array 
Javascript :: checks for valid email address syntax javascript 
Javascript :: swap first and last element in array javascript 
Javascript :: images node backend server 
Javascript :: update password before saving to mongodb 
Javascript :: Looping arrays with for loop 
Javascript :: ucwords javascript 
Javascript :: call function add parameter javascript 
Javascript :: errorMessage is not defined 
Javascript :: read more/less button with smoth expand 
Javascript :: negative indexing in arrays javascript 
Python :: python suppress warnings 
Python :: sqlalchemy python install 
Python :: remove all pyc files 
Python :: get external ip python 
Python :: python open web browser 
Python :: python replace all new lines with space 
Python :: pandas change column to a string 
Python :: sudo python3 -m pip install pyautogui 
Python :: python letter arr 
Python :: discord.py unban command 
Python :: incognito selenium 
Python :: txt to list python 
Python :: get diroctary in python 
ADD CONTENT
Topic
Content
Source link
Name
5+1 =