Reputation: 53
@Input() changeStoreKeyToChangeTypeMapping:Map<any,any>;
ngOnInit() {
this.configToMetadataMap = new Map<any,any>();
this.buildConfigMetaDataMap().subscribe(_ => this.init());
}
private buildConfigMetaDataMap(): Observable<any> {
return forkJoin(
this.changeStoreKeyToChangeTypeMapping.forEach((searchEntry,configKey) => {
this.configDataFetchService.getConfigMetadata(searchEntry.configId).pipe(
tap(metaData => this.configToMetadataMap.set(configKey,metaData))
)
})
);
}
This is giving me Error
ERROR TypeError: You provided 'undefined' where a stream was expected. You can provide an Observable, Promise, Array, or Iterable
I want that i complete all the API calls in the method buildConfigMetaDataMap() and returns a final map so that i can use in init() method
Upvotes: 0
Views: 68
Reputation: 31105
You're missing the keyword return
in the arrow function. Also you could use Array#map
function instead of forEach
. Try the following
private buildConfigMetaDataMap(): Observable <any> {
return forkJoin(
this.changeStoreKeyToChangeTypeMapping.map((searchEntry, configKey) => {
return this.configDataFetchService.getConfigMetadata(searchEntry.configId).pipe(
tap(metaData => this.configToMetadataMap.set(configKey, metaData))
);
})
);
}
Note:
return
, you could refer my answer here.tap
operator. It is better not to resort to tap
side-effect when compute intensive tasks are involved.Upvotes: 1