Deepak Sharma
Deepak Sharma

Reputation: 53

Observable Errror : You provided 'undefined' where

@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

Answers (1)

Barremian
Barremian

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:

  1. To understand why you need the return, you could refer my answer here.
  2. Assuming this question is related to your previous question, I've provided a different answer there that doesn't use RxJS tap operator. It is better not to resort to tap side-effect when compute intensive tasks are involved.

Upvotes: 1

Related Questions