Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Difficulty returning the result of an inner function in Angular / Typescript

I am really new to Angular and Typescript.

I have this function right now

createTranscriptionJob(fileToUpload: File, language: string): Observable<void> {

    this.getSasUrl(fileToUpload.name, language, ldapUserName)
        .subscribe(response => {
            const test = this.upload(response.sasUrl, fileToUpload);
            console.log(test);
        });

    return of();
}

First problem currently is that the createTranscriptionJob function is returning basically nothing.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Second problem is that the createTranscriptionJob function is returning before the completion of the inner upload function call.

Question

I would need the createTranscriptionJob function to return the result of the upload function. How to achieve that?

Something like that, but it’s complaining:
enter image description here

>Solution :

You’ll need to chain your observables with an operator like switchMap.

Doing so, you will need the called to do the subscribe.

createTranscriptionJob(fileToUpload: File, language: string): Observable<void> {
    return this.getSasUrl(fileToUpload.name, language, ldapUserName)
       .pipe(
           switchMap(() =>  this.upload(response.sasUrl, fileToUpload)
        )
       

);
}

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading