Observable.forkJoin and array argument

别等时光非礼了梦想. 提交于 2019-11-27 20:23:32
Sasxa

You need to import operators that are not loaded by default. That's what EXCEPTION Observable.xxxx is not a function usually means. You can either import all operators by adding complete rxjs to your bootstrap, for example:

import 'rxjs/Rx'

or by importing specific operators, in your case:

import 'rxjs/add/observable/forkJoin'

Another observation/suggestion about your code: try to stick with one syntax. You are mixing es5, es6, typescript... and while it is working it will only confuse you in the long run. Also, if you're just starting with Observables, try to avoid new Observable() and use creation operators instead;

processStuff( inputObject ) {
  let observableBatch = [];

  inputObject.forEach(( componentarray, key ) => {
    observableBatch.push( this.http.get( key + '.json').map((res: Response) => res.json()) );
  });

  return Observable.forkJoin(observableBatch);
}

elsewhere() {
  this.processStuff( inputObject )
    .subscribe()
}

Finally, refer to the correct documentation - Angular2 uses RxJS v5 and link you provided is for RxJS v4. Docs are still incomplete for v5, but you can find descriptions in many of the source files.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!