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;
I am trying to understand rxjs (6) and how I should call conditionally make a second http post.
My scenario is that:
- I am/have uploaded a file.
- I get an object identifying the current progress and a filename.
- 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
- 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
add a comment |
I am trying to understand rxjs (6) and how I should call conditionally make a second http post.
My scenario is that:
- I am/have uploaded a file.
- I get an object identifying the current progress and a filename.
- 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
- 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
Something like this? stackoverflow.com/questions/47610150/…
– Oles Savluk
Mar 9 at 8:47
add a comment |
I am trying to understand rxjs (6) and how I should call conditionally make a second http post.
My scenario is that:
- I am/have uploaded a file.
- I get an object identifying the current progress and a filename.
- 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
- 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
I am trying to understand rxjs (6) and how I should call conditionally make a second http post.
My scenario is that:
- I am/have uploaded a file.
- I get an object identifying the current progress and a filename.
- 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
- 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
rxjs
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
add a comment |
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
add a comment |
2 Answers
2
active
oldest
votes
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)
),
);
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
add a comment |
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();
);
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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)
),
);
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
add a comment |
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)
),
);
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
add a comment |
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)
),
);
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)
),
);
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
add a comment |
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
add a comment |
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();
);
add a comment |
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();
);
add a comment |
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();
);
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();
);
answered Mar 9 at 21:55
tony09uktony09uk
1,08832442
1,08832442
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
Something like this? stackoverflow.com/questions/47610150/…
– Oles Savluk
Mar 9 at 8:47