I have a collection of properties that need to be included in a larger mergeMap operation.
this.customFeedsService.postNewSocialMediaFeed(this.newFeed)
.mergeMap( newFeed => this.customFeedsService.postFeedProperties( newFeed.Id, this.feedProps))
.mergeMap(newProps => this.customFeedsService.preloadSocialMediaFeed(newProps.FeedId))
.subscribe(data => console.log(data), err => console.log);
Within my service, I iterate through the properties to generate a single Observable that feeds into the mergeMap process.
public postFeedProperties( feedId: number, props: FeedPropertyApi[] ): Observable<any> {
let observeGroup = new Observable<any>();
for(let prop of props){
prop.FeedId = feedId;
observeGroup.concat(this.apiService.postData(this.feedPropertyApiUrl, prop, true)
.map(res => res.json()));
}
return observeGroup
// return this.apiService.postData(this.feedPropertyApiUrl, props[0], true)
// .map(res => res.json()).concat(this.apiService.postData(this.feedPropertyApiUrl, props[1],true)
// .map(res => res.json())).concat(this.apiService.postData(this.feedPropertyApiUrl, props[2], true)
// .map(res => res.json()));
}
While the commented code works perfectly fine, I encounter a
Cannot read property 'subscribe' of undefined
error when running the loop. What could possibly be causing this issue within the loop?