mergeMap on a list of Ids fails to build
up vote
0
down vote
favorite
What is wrong with the syntax here mergeMap(names => names),
?
getIds(): void {
this.myservice
.getIds.pipe( mergeMap(id => this.getNames(id)),
mergeMap(names => names), toArray() )
}
myservce.ts has the following:
getIds():Observable<Ids>{
const url = 'http://localhost:4000';
return this.http
.post(url, '')
.map(({ Ids }: any) => Ids.map(item => ({Id: item.Id,
Name: item.Name }))) as Observable<Ids>;
}
getNames(data: Ids):Observable<any> {
const url ='http://localhost:5000';
return this.http
.post(url,data)
.pipe(map(({ Results }: any) => Results[0].results.map(item => ({Id: item.ID, Name: item.Name }))));
}
The compiler error is (as a newbie I'm not able to figure out):
ERROR in src/app/cvetable/mcomponent.ts(132,19): error TS2345:
Argument of type '(names: {}) => {}' is not assignable to parameter
of type '(value: {}, index: number) => ObservableInput<any>'.
Type '{}' is not assignable to type 'ObservableInput<any>'.
Type '{}' is not assignable to type 'Iterable<any>'.
Property '[Symbol.iterator]' is missing in type '{}'.
angular http observable
|
show 2 more comments
up vote
0
down vote
favorite
What is wrong with the syntax here mergeMap(names => names),
?
getIds(): void {
this.myservice
.getIds.pipe( mergeMap(id => this.getNames(id)),
mergeMap(names => names), toArray() )
}
myservce.ts has the following:
getIds():Observable<Ids>{
const url = 'http://localhost:4000';
return this.http
.post(url, '')
.map(({ Ids }: any) => Ids.map(item => ({Id: item.Id,
Name: item.Name }))) as Observable<Ids>;
}
getNames(data: Ids):Observable<any> {
const url ='http://localhost:5000';
return this.http
.post(url,data)
.pipe(map(({ Results }: any) => Results[0].results.map(item => ({Id: item.ID, Name: item.Name }))));
}
The compiler error is (as a newbie I'm not able to figure out):
ERROR in src/app/cvetable/mcomponent.ts(132,19): error TS2345:
Argument of type '(names: {}) => {}' is not assignable to parameter
of type '(value: {}, index: number) => ObservableInput<any>'.
Type '{}' is not assignable to type 'ObservableInput<any>'.
Type '{}' is not assignable to type 'Iterable<any>'.
Property '[Symbol.iterator]' is missing in type '{}'.
angular http observable
can u share the editable stackblitz link
– NinjaJami
Nov 10 at 18:50
@NinjaJami link is here stackblitz.com/edit/… but doesn't seems to be rigid enough :(
– Pankaj Parkar
Nov 10 at 18:51
StackBlitz removes the code that doesnt compile :( Hence posting the code above.
– anglee
Nov 10 at 19:03
could you explain in words what you are trying to accomplish? you seems to stick onmergeMap
but maybe this is not suitable for your need ... or maybe it is but without context its hard to tell
– j3ff
Nov 10 at 19:24
@anglee are you missing () after this.myservice.getIds ?
– A.Winnen
Nov 10 at 19:55
|
show 2 more comments
up vote
0
down vote
favorite
up vote
0
down vote
favorite
What is wrong with the syntax here mergeMap(names => names),
?
getIds(): void {
this.myservice
.getIds.pipe( mergeMap(id => this.getNames(id)),
mergeMap(names => names), toArray() )
}
myservce.ts has the following:
getIds():Observable<Ids>{
const url = 'http://localhost:4000';
return this.http
.post(url, '')
.map(({ Ids }: any) => Ids.map(item => ({Id: item.Id,
Name: item.Name }))) as Observable<Ids>;
}
getNames(data: Ids):Observable<any> {
const url ='http://localhost:5000';
return this.http
.post(url,data)
.pipe(map(({ Results }: any) => Results[0].results.map(item => ({Id: item.ID, Name: item.Name }))));
}
The compiler error is (as a newbie I'm not able to figure out):
ERROR in src/app/cvetable/mcomponent.ts(132,19): error TS2345:
Argument of type '(names: {}) => {}' is not assignable to parameter
of type '(value: {}, index: number) => ObservableInput<any>'.
Type '{}' is not assignable to type 'ObservableInput<any>'.
Type '{}' is not assignable to type 'Iterable<any>'.
Property '[Symbol.iterator]' is missing in type '{}'.
angular http observable
What is wrong with the syntax here mergeMap(names => names),
?
getIds(): void {
this.myservice
.getIds.pipe( mergeMap(id => this.getNames(id)),
mergeMap(names => names), toArray() )
}
myservce.ts has the following:
getIds():Observable<Ids>{
const url = 'http://localhost:4000';
return this.http
.post(url, '')
.map(({ Ids }: any) => Ids.map(item => ({Id: item.Id,
Name: item.Name }))) as Observable<Ids>;
}
getNames(data: Ids):Observable<any> {
const url ='http://localhost:5000';
return this.http
.post(url,data)
.pipe(map(({ Results }: any) => Results[0].results.map(item => ({Id: item.ID, Name: item.Name }))));
}
The compiler error is (as a newbie I'm not able to figure out):
ERROR in src/app/cvetable/mcomponent.ts(132,19): error TS2345:
Argument of type '(names: {}) => {}' is not assignable to parameter
of type '(value: {}, index: number) => ObservableInput<any>'.
Type '{}' is not assignable to type 'ObservableInput<any>'.
Type '{}' is not assignable to type 'Iterable<any>'.
Property '[Symbol.iterator]' is missing in type '{}'.
angular http observable
angular http observable
edited Nov 10 at 18:59
asked Nov 10 at 18:46
anglee
124
124
can u share the editable stackblitz link
– NinjaJami
Nov 10 at 18:50
@NinjaJami link is here stackblitz.com/edit/… but doesn't seems to be rigid enough :(
– Pankaj Parkar
Nov 10 at 18:51
StackBlitz removes the code that doesnt compile :( Hence posting the code above.
– anglee
Nov 10 at 19:03
could you explain in words what you are trying to accomplish? you seems to stick onmergeMap
but maybe this is not suitable for your need ... or maybe it is but without context its hard to tell
– j3ff
Nov 10 at 19:24
@anglee are you missing () after this.myservice.getIds ?
– A.Winnen
Nov 10 at 19:55
|
show 2 more comments
can u share the editable stackblitz link
– NinjaJami
Nov 10 at 18:50
@NinjaJami link is here stackblitz.com/edit/… but doesn't seems to be rigid enough :(
– Pankaj Parkar
Nov 10 at 18:51
StackBlitz removes the code that doesnt compile :( Hence posting the code above.
– anglee
Nov 10 at 19:03
could you explain in words what you are trying to accomplish? you seems to stick onmergeMap
but maybe this is not suitable for your need ... or maybe it is but without context its hard to tell
– j3ff
Nov 10 at 19:24
@anglee are you missing () after this.myservice.getIds ?
– A.Winnen
Nov 10 at 19:55
can u share the editable stackblitz link
– NinjaJami
Nov 10 at 18:50
can u share the editable stackblitz link
– NinjaJami
Nov 10 at 18:50
@NinjaJami link is here stackblitz.com/edit/… but doesn't seems to be rigid enough :(
– Pankaj Parkar
Nov 10 at 18:51
@NinjaJami link is here stackblitz.com/edit/… but doesn't seems to be rigid enough :(
– Pankaj Parkar
Nov 10 at 18:51
StackBlitz removes the code that doesnt compile :( Hence posting the code above.
– anglee
Nov 10 at 19:03
StackBlitz removes the code that doesnt compile :( Hence posting the code above.
– anglee
Nov 10 at 19:03
could you explain in words what you are trying to accomplish? you seems to stick on
mergeMap
but maybe this is not suitable for your need ... or maybe it is but without context its hard to tell– j3ff
Nov 10 at 19:24
could you explain in words what you are trying to accomplish? you seems to stick on
mergeMap
but maybe this is not suitable for your need ... or maybe it is but without context its hard to tell– j3ff
Nov 10 at 19:24
@anglee are you missing () after this.myservice.getIds ?
– A.Winnen
Nov 10 at 19:55
@anglee are you missing () after this.myservice.getIds ?
– A.Winnen
Nov 10 at 19:55
|
show 2 more comments
2 Answers
2
active
oldest
votes
up vote
0
down vote
There's something seriously wrong with the getIds
method in your Service:
Here's how it should be. Since you're using HttpClient
and your eg is in Angular 7 which uses Rxjs 6+, you'll have to chain a .pipe
call to your Observable value in order to apply operators on it. Inside the .pipe
call, you can then place a list of comma separated operators:
getIds(obj):Observable<Ids>{
return this.http
.post(this.url, obj)
.pipe(
map((Ids: any) => Ids.map(item => ({Id: item.Id, Name: item.Name }) ) )
)
}
Here's an Updated StackBlitz with the errors fixed.
OK. I've made the change. The compile error is still at the same on the linemergeMap(names => names),
. Can you please see what I'm missing there?
– anglee
Nov 10 at 19:18
I'll need you to share a minimal stackblitz sample replicating your issue. The one you shared previously lacks a lot of things. Please fix it so that it replicates just the issue that you're facing. Please fix other issues on the StackBlitz that are there due to not adding implementation details.
– SiddAjmera
Nov 10 at 19:24
The StackBlitz runs into other issues. Eg. (no Observable module in rxjs/Rx). I'm still working on creating a simpler example with just this problem.
– anglee
Nov 10 at 21:10
The StackBlitz link has relevant parts of the code. Please take a look. I'm looking to find a fix for the compile failure that seems like a syntax issue.
– anglee
Nov 11 at 5:38
add a comment |
up vote
0
down vote
You should use switchMap
instead of mergeMap
getIds(): void {
this.myservice
.getIds.pipe(switchMap(id => this.getNames(id)))
}
OK. But the compile failure is on a diff line. The editable StackBlitz link link has the relevant parts of the code.
– anglee
Nov 11 at 5:35
Your demo is completely broken. Are expecting others to fix your compilation and syntax issue along with current issue ?
– Sunil Singh
Nov 11 at 5:43
Sorry; I am only expecting to hear about what is wrong with the syntax in the line that I point out. I cannot post the code because the framework on stackblitz is not the same version as what I have and hence cannot post a working demo with my code.
– anglee
Nov 11 at 5:55
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
There's something seriously wrong with the getIds
method in your Service:
Here's how it should be. Since you're using HttpClient
and your eg is in Angular 7 which uses Rxjs 6+, you'll have to chain a .pipe
call to your Observable value in order to apply operators on it. Inside the .pipe
call, you can then place a list of comma separated operators:
getIds(obj):Observable<Ids>{
return this.http
.post(this.url, obj)
.pipe(
map((Ids: any) => Ids.map(item => ({Id: item.Id, Name: item.Name }) ) )
)
}
Here's an Updated StackBlitz with the errors fixed.
OK. I've made the change. The compile error is still at the same on the linemergeMap(names => names),
. Can you please see what I'm missing there?
– anglee
Nov 10 at 19:18
I'll need you to share a minimal stackblitz sample replicating your issue. The one you shared previously lacks a lot of things. Please fix it so that it replicates just the issue that you're facing. Please fix other issues on the StackBlitz that are there due to not adding implementation details.
– SiddAjmera
Nov 10 at 19:24
The StackBlitz runs into other issues. Eg. (no Observable module in rxjs/Rx). I'm still working on creating a simpler example with just this problem.
– anglee
Nov 10 at 21:10
The StackBlitz link has relevant parts of the code. Please take a look. I'm looking to find a fix for the compile failure that seems like a syntax issue.
– anglee
Nov 11 at 5:38
add a comment |
up vote
0
down vote
There's something seriously wrong with the getIds
method in your Service:
Here's how it should be. Since you're using HttpClient
and your eg is in Angular 7 which uses Rxjs 6+, you'll have to chain a .pipe
call to your Observable value in order to apply operators on it. Inside the .pipe
call, you can then place a list of comma separated operators:
getIds(obj):Observable<Ids>{
return this.http
.post(this.url, obj)
.pipe(
map((Ids: any) => Ids.map(item => ({Id: item.Id, Name: item.Name }) ) )
)
}
Here's an Updated StackBlitz with the errors fixed.
OK. I've made the change. The compile error is still at the same on the linemergeMap(names => names),
. Can you please see what I'm missing there?
– anglee
Nov 10 at 19:18
I'll need you to share a minimal stackblitz sample replicating your issue. The one you shared previously lacks a lot of things. Please fix it so that it replicates just the issue that you're facing. Please fix other issues on the StackBlitz that are there due to not adding implementation details.
– SiddAjmera
Nov 10 at 19:24
The StackBlitz runs into other issues. Eg. (no Observable module in rxjs/Rx). I'm still working on creating a simpler example with just this problem.
– anglee
Nov 10 at 21:10
The StackBlitz link has relevant parts of the code. Please take a look. I'm looking to find a fix for the compile failure that seems like a syntax issue.
– anglee
Nov 11 at 5:38
add a comment |
up vote
0
down vote
up vote
0
down vote
There's something seriously wrong with the getIds
method in your Service:
Here's how it should be. Since you're using HttpClient
and your eg is in Angular 7 which uses Rxjs 6+, you'll have to chain a .pipe
call to your Observable value in order to apply operators on it. Inside the .pipe
call, you can then place a list of comma separated operators:
getIds(obj):Observable<Ids>{
return this.http
.post(this.url, obj)
.pipe(
map((Ids: any) => Ids.map(item => ({Id: item.Id, Name: item.Name }) ) )
)
}
Here's an Updated StackBlitz with the errors fixed.
There's something seriously wrong with the getIds
method in your Service:
Here's how it should be. Since you're using HttpClient
and your eg is in Angular 7 which uses Rxjs 6+, you'll have to chain a .pipe
call to your Observable value in order to apply operators on it. Inside the .pipe
call, you can then place a list of comma separated operators:
getIds(obj):Observable<Ids>{
return this.http
.post(this.url, obj)
.pipe(
map((Ids: any) => Ids.map(item => ({Id: item.Id, Name: item.Name }) ) )
)
}
Here's an Updated StackBlitz with the errors fixed.
answered Nov 10 at 19:05
SiddAjmera
9,65821037
9,65821037
OK. I've made the change. The compile error is still at the same on the linemergeMap(names => names),
. Can you please see what I'm missing there?
– anglee
Nov 10 at 19:18
I'll need you to share a minimal stackblitz sample replicating your issue. The one you shared previously lacks a lot of things. Please fix it so that it replicates just the issue that you're facing. Please fix other issues on the StackBlitz that are there due to not adding implementation details.
– SiddAjmera
Nov 10 at 19:24
The StackBlitz runs into other issues. Eg. (no Observable module in rxjs/Rx). I'm still working on creating a simpler example with just this problem.
– anglee
Nov 10 at 21:10
The StackBlitz link has relevant parts of the code. Please take a look. I'm looking to find a fix for the compile failure that seems like a syntax issue.
– anglee
Nov 11 at 5:38
add a comment |
OK. I've made the change. The compile error is still at the same on the linemergeMap(names => names),
. Can you please see what I'm missing there?
– anglee
Nov 10 at 19:18
I'll need you to share a minimal stackblitz sample replicating your issue. The one you shared previously lacks a lot of things. Please fix it so that it replicates just the issue that you're facing. Please fix other issues on the StackBlitz that are there due to not adding implementation details.
– SiddAjmera
Nov 10 at 19:24
The StackBlitz runs into other issues. Eg. (no Observable module in rxjs/Rx). I'm still working on creating a simpler example with just this problem.
– anglee
Nov 10 at 21:10
The StackBlitz link has relevant parts of the code. Please take a look. I'm looking to find a fix for the compile failure that seems like a syntax issue.
– anglee
Nov 11 at 5:38
OK. I've made the change. The compile error is still at the same on the line
mergeMap(names => names),
. Can you please see what I'm missing there?– anglee
Nov 10 at 19:18
OK. I've made the change. The compile error is still at the same on the line
mergeMap(names => names),
. Can you please see what I'm missing there?– anglee
Nov 10 at 19:18
I'll need you to share a minimal stackblitz sample replicating your issue. The one you shared previously lacks a lot of things. Please fix it so that it replicates just the issue that you're facing. Please fix other issues on the StackBlitz that are there due to not adding implementation details.
– SiddAjmera
Nov 10 at 19:24
I'll need you to share a minimal stackblitz sample replicating your issue. The one you shared previously lacks a lot of things. Please fix it so that it replicates just the issue that you're facing. Please fix other issues on the StackBlitz that are there due to not adding implementation details.
– SiddAjmera
Nov 10 at 19:24
The StackBlitz runs into other issues. Eg. (no Observable module in rxjs/Rx). I'm still working on creating a simpler example with just this problem.
– anglee
Nov 10 at 21:10
The StackBlitz runs into other issues. Eg. (no Observable module in rxjs/Rx). I'm still working on creating a simpler example with just this problem.
– anglee
Nov 10 at 21:10
The StackBlitz link has relevant parts of the code. Please take a look. I'm looking to find a fix for the compile failure that seems like a syntax issue.
– anglee
Nov 11 at 5:38
The StackBlitz link has relevant parts of the code. Please take a look. I'm looking to find a fix for the compile failure that seems like a syntax issue.
– anglee
Nov 11 at 5:38
add a comment |
up vote
0
down vote
You should use switchMap
instead of mergeMap
getIds(): void {
this.myservice
.getIds.pipe(switchMap(id => this.getNames(id)))
}
OK. But the compile failure is on a diff line. The editable StackBlitz link link has the relevant parts of the code.
– anglee
Nov 11 at 5:35
Your demo is completely broken. Are expecting others to fix your compilation and syntax issue along with current issue ?
– Sunil Singh
Nov 11 at 5:43
Sorry; I am only expecting to hear about what is wrong with the syntax in the line that I point out. I cannot post the code because the framework on stackblitz is not the same version as what I have and hence cannot post a working demo with my code.
– anglee
Nov 11 at 5:55
add a comment |
up vote
0
down vote
You should use switchMap
instead of mergeMap
getIds(): void {
this.myservice
.getIds.pipe(switchMap(id => this.getNames(id)))
}
OK. But the compile failure is on a diff line. The editable StackBlitz link link has the relevant parts of the code.
– anglee
Nov 11 at 5:35
Your demo is completely broken. Are expecting others to fix your compilation and syntax issue along with current issue ?
– Sunil Singh
Nov 11 at 5:43
Sorry; I am only expecting to hear about what is wrong with the syntax in the line that I point out. I cannot post the code because the framework on stackblitz is not the same version as what I have and hence cannot post a working demo with my code.
– anglee
Nov 11 at 5:55
add a comment |
up vote
0
down vote
up vote
0
down vote
You should use switchMap
instead of mergeMap
getIds(): void {
this.myservice
.getIds.pipe(switchMap(id => this.getNames(id)))
}
You should use switchMap
instead of mergeMap
getIds(): void {
this.myservice
.getIds.pipe(switchMap(id => this.getNames(id)))
}
answered Nov 11 at 4:24
Sunil Singh
5,4571625
5,4571625
OK. But the compile failure is on a diff line. The editable StackBlitz link link has the relevant parts of the code.
– anglee
Nov 11 at 5:35
Your demo is completely broken. Are expecting others to fix your compilation and syntax issue along with current issue ?
– Sunil Singh
Nov 11 at 5:43
Sorry; I am only expecting to hear about what is wrong with the syntax in the line that I point out. I cannot post the code because the framework on stackblitz is not the same version as what I have and hence cannot post a working demo with my code.
– anglee
Nov 11 at 5:55
add a comment |
OK. But the compile failure is on a diff line. The editable StackBlitz link link has the relevant parts of the code.
– anglee
Nov 11 at 5:35
Your demo is completely broken. Are expecting others to fix your compilation and syntax issue along with current issue ?
– Sunil Singh
Nov 11 at 5:43
Sorry; I am only expecting to hear about what is wrong with the syntax in the line that I point out. I cannot post the code because the framework on stackblitz is not the same version as what I have and hence cannot post a working demo with my code.
– anglee
Nov 11 at 5:55
OK. But the compile failure is on a diff line. The editable StackBlitz link link has the relevant parts of the code.
– anglee
Nov 11 at 5:35
OK. But the compile failure is on a diff line. The editable StackBlitz link link has the relevant parts of the code.
– anglee
Nov 11 at 5:35
Your demo is completely broken. Are expecting others to fix your compilation and syntax issue along with current issue ?
– Sunil Singh
Nov 11 at 5:43
Your demo is completely broken. Are expecting others to fix your compilation and syntax issue along with current issue ?
– Sunil Singh
Nov 11 at 5:43
Sorry; I am only expecting to hear about what is wrong with the syntax in the line that I point out. I cannot post the code because the framework on stackblitz is not the same version as what I have and hence cannot post a working demo with my code.
– anglee
Nov 11 at 5:55
Sorry; I am only expecting to hear about what is wrong with the syntax in the line that I point out. I cannot post the code because the framework on stackblitz is not the same version as what I have and hence cannot post a working demo with my code.
– anglee
Nov 11 at 5:55
add a comment |
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%2f53242276%2fmergemap-on-a-list-of-ids-fails-to-build%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
can u share the editable stackblitz link
– NinjaJami
Nov 10 at 18:50
@NinjaJami link is here stackblitz.com/edit/… but doesn't seems to be rigid enough :(
– Pankaj Parkar
Nov 10 at 18:51
StackBlitz removes the code that doesnt compile :( Hence posting the code above.
– anglee
Nov 10 at 19:03
could you explain in words what you are trying to accomplish? you seems to stick on
mergeMap
but maybe this is not suitable for your need ... or maybe it is but without context its hard to tell– j3ff
Nov 10 at 19:24
@anglee are you missing () after this.myservice.getIds ?
– A.Winnen
Nov 10 at 19:55