Rxjs conditionally make a second http callrxjs condition inside flatmapAngular HTTP GET with TypeScript error http.get(…).map is not a function in [null]What is the correct way to share the result of an Angular Http network call in RxJs 5?Angular/RxJs When should I unsubscribe from `Subscription`Retry all HTTP calls if one fails in Angular 2 when one is dependant on anotherAngular 5 - persist the data and avoid subsequent API callsUsing RxJS to Send One Network RequestAngular rxjs private subject + public observable setupCancel concurrency HTTP requests after unsubscriptionRxJS iif arguments are called when shouldn'tIn RxJS, map not executing inner mapped observable

Is it inappropriate for a student to attend their mentor's dissertation defense?

Can I ask the recruiters in my resume to put the reason why I am rejected?

How could indestructible materials be used in power generation?

If human space travel is limited by the G force vulnerability, is there a way to counter G forces?

How to model explosives?

In Romance of the Three Kingdoms why do people still use bamboo sticks when papers are already invented?

Why is it a bad idea to hire a hitman to eliminate most corrupt politicians?

How do I write bicross product symbols in latex?

When a company launches a new product do they "come out" with a new product or do they "come up" with a new product?

Can I use a neutral wire from another outlet to repair a broken neutral?

How to draw the figure with four pentagons?

Twin primes whose sum is a cube

SSH "lag" in LAN on some machines, mixed distros

Python: return float 1.0 as int 1 but float 1.5 as float 1.5

Is Lorentz symmetry broken if SUSY is broken?

Could gravitational lensing be used to protect a spaceship from a laser?

How to prevent "they're falling in love" trope

How can I tell someone that I want to be his or her friend?

Can one be a co-translator of a book, if he does not know the language that the book is translated into?

How to say in German "enjoying home comforts"

What is the word for reserving something for yourself before others do?

UK: Is there precedent for the governments e-petition site changing the direction of a government decision?

What does it mean to describe someone as a butt steak?

Blender 2.8 I can't see vertices, edges or faces in edit mode



Rxjs conditionally make a second http call


rxjs condition inside flatmapAngular HTTP GET with TypeScript error http.get(…).map is not a function in [null]What is the correct way to share the result of an Angular Http network call in RxJs 5?Angular/RxJs When should I unsubscribe from `Subscription`Retry all HTTP calls if one fails in Angular 2 when one is dependant on anotherAngular 5 - persist the data and avoid subsequent API callsUsing RxJS to Send One Network RequestAngular rxjs private subject + public observable setupCancel concurrency HTTP requests after unsubscriptionRxJS iif arguments are called when shouldn'tIn RxJS, map not executing inner mapped observable






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I am trying to understand rxjs (6) and how I should call conditionally make a second http post.



My scenario is that:



  1. I am/have uploaded a file.

  2. I get an object identifying the current progress and a filename.

  3. If the current progress is 100 I want to make the second http post and on success of that second call return the progress and the filename

  4. If the current progress is less than 100 simply return the progress and filename

My class



export class BasePortalDetailsManagerService 
updateCertificate(file: File): Observable<IUploadProgress>
return this._azureBlobStorage
.uploadCertificateToBlobStorage2(file, this.portalKey)
.pipe(
map(progress => this.mapProgress2(progress))
);


private mapProgress2(fileProgress: FileProgress): IUploadProgress
if (fileProgress.Progress === 100)
console.log('I can do something here but there must be a better way');

else
return
filename: fileProgress.FilePath,
progress: fileProgress.Progress
;





I have been watching and reading various stuff and the only that seems to happen is, it convinces me my way is wrong. I cant seem to get my head round the various tutorials.



various links I've followed



rxjs quick start



cory rylan



rxjs where is the if/else










share|improve this question






















  • Something like this? stackoverflow.com/questions/47610150/…

    – Oles Savluk
    Mar 9 at 8:47

















0















I am trying to understand rxjs (6) and how I should call conditionally make a second http post.



My scenario is that:



  1. I am/have uploaded a file.

  2. I get an object identifying the current progress and a filename.

  3. If the current progress is 100 I want to make the second http post and on success of that second call return the progress and the filename

  4. If the current progress is less than 100 simply return the progress and filename

My class



export class BasePortalDetailsManagerService 
updateCertificate(file: File): Observable<IUploadProgress>
return this._azureBlobStorage
.uploadCertificateToBlobStorage2(file, this.portalKey)
.pipe(
map(progress => this.mapProgress2(progress))
);


private mapProgress2(fileProgress: FileProgress): IUploadProgress
if (fileProgress.Progress === 100)
console.log('I can do something here but there must be a better way');

else
return
filename: fileProgress.FilePath,
progress: fileProgress.Progress
;





I have been watching and reading various stuff and the only that seems to happen is, it convinces me my way is wrong. I cant seem to get my head round the various tutorials.



various links I've followed



rxjs quick start



cory rylan



rxjs where is the if/else










share|improve this question






















  • Something like this? stackoverflow.com/questions/47610150/…

    – Oles Savluk
    Mar 9 at 8:47













0












0








0








I am trying to understand rxjs (6) and how I should call conditionally make a second http post.



My scenario is that:



  1. I am/have uploaded a file.

  2. I get an object identifying the current progress and a filename.

  3. If the current progress is 100 I want to make the second http post and on success of that second call return the progress and the filename

  4. If the current progress is less than 100 simply return the progress and filename

My class



export class BasePortalDetailsManagerService 
updateCertificate(file: File): Observable<IUploadProgress>
return this._azureBlobStorage
.uploadCertificateToBlobStorage2(file, this.portalKey)
.pipe(
map(progress => this.mapProgress2(progress))
);


private mapProgress2(fileProgress: FileProgress): IUploadProgress
if (fileProgress.Progress === 100)
console.log('I can do something here but there must be a better way');

else
return
filename: fileProgress.FilePath,
progress: fileProgress.Progress
;





I have been watching and reading various stuff and the only that seems to happen is, it convinces me my way is wrong. I cant seem to get my head round the various tutorials.



various links I've followed



rxjs quick start



cory rylan



rxjs where is the if/else










share|improve this question














I am trying to understand rxjs (6) and how I should call conditionally make a second http post.



My scenario is that:



  1. I am/have uploaded a file.

  2. I get an object identifying the current progress and a filename.

  3. If the current progress is 100 I want to make the second http post and on success of that second call return the progress and the filename

  4. If the current progress is less than 100 simply return the progress and filename

My class



export class BasePortalDetailsManagerService 
updateCertificate(file: File): Observable<IUploadProgress>
return this._azureBlobStorage
.uploadCertificateToBlobStorage2(file, this.portalKey)
.pipe(
map(progress => this.mapProgress2(progress))
);


private mapProgress2(fileProgress: FileProgress): IUploadProgress
if (fileProgress.Progress === 100)
console.log('I can do something here but there must be a better way');

else
return
filename: fileProgress.FilePath,
progress: fileProgress.Progress
;





I have been watching and reading various stuff and the only that seems to happen is, it convinces me my way is wrong. I cant seem to get my head round the various tutorials.



various links I've followed



rxjs quick start



cory rylan



rxjs where is the if/else







rxjs






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 8 at 23:28









tony09uktony09uk

1,08832442




1,08832442












  • Something like this? stackoverflow.com/questions/47610150/…

    – Oles Savluk
    Mar 9 at 8:47

















  • Something like this? stackoverflow.com/questions/47610150/…

    – Oles Savluk
    Mar 9 at 8:47
















Something like this? stackoverflow.com/questions/47610150/…

– Oles Savluk
Mar 9 at 8:47





Something like this? stackoverflow.com/questions/47610150/…

– Oles Savluk
Mar 9 at 8:47












2 Answers
2






active

oldest

votes


















0














Instead of map use concatMap and depending on progress return this original object wrapped in an Observable with of(progress) or return another Observable that makes the second request and map its result to progress:



this._azureBlobStorage.uploadCertificateToBlobStorage2(file, this.portalKey).pipe(
concatMap(progress => progress.Progress === 100
? this.mapProgress2(progress).pipe(
map(filename => ( // This could go inside `mapProgress2` as well
filename: progress.FilePath,
progress: progress.Progress
)),
)
: of(progress)
),
);





share|improve this answer























  • Thanks for your reply. I'm feeling a little lost as I can't call pipe on mapProgress2 as it only returns IUploadProgress, not an observable. Also do I make my second http call in of or concatMap?

    – tony09uk
    Mar 9 at 17:51


















0














I was able to resolve my issue thanks to @martin pointing me in the right direction.



I change mapProgress2() return type to be Observable<IUploadProgress> then use flatMap to flatten the inner observable.



My knowledge of rxjs is very limited but I believe for scenario flatMap, switchMap or concatMap would suffice. @martin suggested concatMap and after reading the docs I agree.



From The RXJS docs




flatMap: flatMap is an alias for mergeMap!



mergeMap: If you would like more than one inner subscription to be maintained, try mergeMap



switchMap: If only one inner subscription should be active at a time, try switchMap



concatMap: If the order of emission and subscription of inner observables is important, try concatMap




updateCertificate(file: File): Observable<IUploadProgress> 
return this._azureBlobStorage
.uploadCertificateToBlobStorage2(file, this.portalKey)
.pipe(
flatMap(progress => this.mapProgress2(progress))
);


private mapProgress2(fileProgress: IUploadProgress): Observable<IUploadProgress>
if (fileProgress.progress === 100)
return this._httpClient.post(this._portalDetails + 'certificatePath', JSON.stringify(fileProgress.filename))
.pipe(map(res => fileProgress));
else
return Observable.create(function(observer)
observer.next(fileProgress);
observer.complete();
);







share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55072397%2frxjs-conditionally-make-a-second-http-call%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Instead of map use concatMap and depending on progress return this original object wrapped in an Observable with of(progress) or return another Observable that makes the second request and map its result to progress:



    this._azureBlobStorage.uploadCertificateToBlobStorage2(file, this.portalKey).pipe(
    concatMap(progress => progress.Progress === 100
    ? this.mapProgress2(progress).pipe(
    map(filename => ( // This could go inside `mapProgress2` as well
    filename: progress.FilePath,
    progress: progress.Progress
    )),
    )
    : of(progress)
    ),
    );





    share|improve this answer























    • Thanks for your reply. I'm feeling a little lost as I can't call pipe on mapProgress2 as it only returns IUploadProgress, not an observable. Also do I make my second http call in of or concatMap?

      – tony09uk
      Mar 9 at 17:51















    0














    Instead of map use concatMap and depending on progress return this original object wrapped in an Observable with of(progress) or return another Observable that makes the second request and map its result to progress:



    this._azureBlobStorage.uploadCertificateToBlobStorage2(file, this.portalKey).pipe(
    concatMap(progress => progress.Progress === 100
    ? this.mapProgress2(progress).pipe(
    map(filename => ( // This could go inside `mapProgress2` as well
    filename: progress.FilePath,
    progress: progress.Progress
    )),
    )
    : of(progress)
    ),
    );





    share|improve this answer























    • Thanks for your reply. I'm feeling a little lost as I can't call pipe on mapProgress2 as it only returns IUploadProgress, not an observable. Also do I make my second http call in of or concatMap?

      – tony09uk
      Mar 9 at 17:51













    0












    0








    0







    Instead of map use concatMap and depending on progress return this original object wrapped in an Observable with of(progress) or return another Observable that makes the second request and map its result to progress:



    this._azureBlobStorage.uploadCertificateToBlobStorage2(file, this.portalKey).pipe(
    concatMap(progress => progress.Progress === 100
    ? this.mapProgress2(progress).pipe(
    map(filename => ( // This could go inside `mapProgress2` as well
    filename: progress.FilePath,
    progress: progress.Progress
    )),
    )
    : of(progress)
    ),
    );





    share|improve this answer













    Instead of map use concatMap and depending on progress return this original object wrapped in an Observable with of(progress) or return another Observable that makes the second request and map its result to progress:



    this._azureBlobStorage.uploadCertificateToBlobStorage2(file, this.portalKey).pipe(
    concatMap(progress => progress.Progress === 100
    ? this.mapProgress2(progress).pipe(
    map(filename => ( // This could go inside `mapProgress2` as well
    filename: progress.FilePath,
    progress: progress.Progress
    )),
    )
    : of(progress)
    ),
    );






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Mar 9 at 13:57









    martinmartin

    46.8k1195138




    46.8k1195138












    • Thanks for your reply. I'm feeling a little lost as I can't call pipe on mapProgress2 as it only returns IUploadProgress, not an observable. Also do I make my second http call in of or concatMap?

      – tony09uk
      Mar 9 at 17:51

















    • Thanks for your reply. I'm feeling a little lost as I can't call pipe on mapProgress2 as it only returns IUploadProgress, not an observable. Also do I make my second http call in of or concatMap?

      – tony09uk
      Mar 9 at 17:51
















    Thanks for your reply. I'm feeling a little lost as I can't call pipe on mapProgress2 as it only returns IUploadProgress, not an observable. Also do I make my second http call in of or concatMap?

    – tony09uk
    Mar 9 at 17:51





    Thanks for your reply. I'm feeling a little lost as I can't call pipe on mapProgress2 as it only returns IUploadProgress, not an observable. Also do I make my second http call in of or concatMap?

    – tony09uk
    Mar 9 at 17:51













    0














    I was able to resolve my issue thanks to @martin pointing me in the right direction.



    I change mapProgress2() return type to be Observable<IUploadProgress> then use flatMap to flatten the inner observable.



    My knowledge of rxjs is very limited but I believe for scenario flatMap, switchMap or concatMap would suffice. @martin suggested concatMap and after reading the docs I agree.



    From The RXJS docs




    flatMap: flatMap is an alias for mergeMap!



    mergeMap: If you would like more than one inner subscription to be maintained, try mergeMap



    switchMap: If only one inner subscription should be active at a time, try switchMap



    concatMap: If the order of emission and subscription of inner observables is important, try concatMap




    updateCertificate(file: File): Observable<IUploadProgress> 
    return this._azureBlobStorage
    .uploadCertificateToBlobStorage2(file, this.portalKey)
    .pipe(
    flatMap(progress => this.mapProgress2(progress))
    );


    private mapProgress2(fileProgress: IUploadProgress): Observable<IUploadProgress>
    if (fileProgress.progress === 100)
    return this._httpClient.post(this._portalDetails + 'certificatePath', JSON.stringify(fileProgress.filename))
    .pipe(map(res => fileProgress));
    else
    return Observable.create(function(observer)
    observer.next(fileProgress);
    observer.complete();
    );







    share|improve this answer



























      0














      I was able to resolve my issue thanks to @martin pointing me in the right direction.



      I change mapProgress2() return type to be Observable<IUploadProgress> then use flatMap to flatten the inner observable.



      My knowledge of rxjs is very limited but I believe for scenario flatMap, switchMap or concatMap would suffice. @martin suggested concatMap and after reading the docs I agree.



      From The RXJS docs




      flatMap: flatMap is an alias for mergeMap!



      mergeMap: If you would like more than one inner subscription to be maintained, try mergeMap



      switchMap: If only one inner subscription should be active at a time, try switchMap



      concatMap: If the order of emission and subscription of inner observables is important, try concatMap




      updateCertificate(file: File): Observable<IUploadProgress> 
      return this._azureBlobStorage
      .uploadCertificateToBlobStorage2(file, this.portalKey)
      .pipe(
      flatMap(progress => this.mapProgress2(progress))
      );


      private mapProgress2(fileProgress: IUploadProgress): Observable<IUploadProgress>
      if (fileProgress.progress === 100)
      return this._httpClient.post(this._portalDetails + 'certificatePath', JSON.stringify(fileProgress.filename))
      .pipe(map(res => fileProgress));
      else
      return Observable.create(function(observer)
      observer.next(fileProgress);
      observer.complete();
      );







      share|improve this answer

























        0












        0








        0







        I was able to resolve my issue thanks to @martin pointing me in the right direction.



        I change mapProgress2() return type to be Observable<IUploadProgress> then use flatMap to flatten the inner observable.



        My knowledge of rxjs is very limited but I believe for scenario flatMap, switchMap or concatMap would suffice. @martin suggested concatMap and after reading the docs I agree.



        From The RXJS docs




        flatMap: flatMap is an alias for mergeMap!



        mergeMap: If you would like more than one inner subscription to be maintained, try mergeMap



        switchMap: If only one inner subscription should be active at a time, try switchMap



        concatMap: If the order of emission and subscription of inner observables is important, try concatMap




        updateCertificate(file: File): Observable<IUploadProgress> 
        return this._azureBlobStorage
        .uploadCertificateToBlobStorage2(file, this.portalKey)
        .pipe(
        flatMap(progress => this.mapProgress2(progress))
        );


        private mapProgress2(fileProgress: IUploadProgress): Observable<IUploadProgress>
        if (fileProgress.progress === 100)
        return this._httpClient.post(this._portalDetails + 'certificatePath', JSON.stringify(fileProgress.filename))
        .pipe(map(res => fileProgress));
        else
        return Observable.create(function(observer)
        observer.next(fileProgress);
        observer.complete();
        );







        share|improve this answer













        I was able to resolve my issue thanks to @martin pointing me in the right direction.



        I change mapProgress2() return type to be Observable<IUploadProgress> then use flatMap to flatten the inner observable.



        My knowledge of rxjs is very limited but I believe for scenario flatMap, switchMap or concatMap would suffice. @martin suggested concatMap and after reading the docs I agree.



        From The RXJS docs




        flatMap: flatMap is an alias for mergeMap!



        mergeMap: If you would like more than one inner subscription to be maintained, try mergeMap



        switchMap: If only one inner subscription should be active at a time, try switchMap



        concatMap: If the order of emission and subscription of inner observables is important, try concatMap




        updateCertificate(file: File): Observable<IUploadProgress> 
        return this._azureBlobStorage
        .uploadCertificateToBlobStorage2(file, this.portalKey)
        .pipe(
        flatMap(progress => this.mapProgress2(progress))
        );


        private mapProgress2(fileProgress: IUploadProgress): Observable<IUploadProgress>
        if (fileProgress.progress === 100)
        return this._httpClient.post(this._portalDetails + 'certificatePath', JSON.stringify(fileProgress.filename))
        .pipe(map(res => fileProgress));
        else
        return Observable.create(function(observer)
        observer.next(fileProgress);
        observer.complete();
        );








        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 9 at 21:55









        tony09uktony09uk

        1,08832442




        1,08832442



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55072397%2frxjs-conditionally-make-a-second-http-call%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

            2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived

            Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme