简体   繁体   English

Angular rxjs映射管道给出了“此”上下文问题

[英]Angular rxjs map pipe gives 'this' context issue

I Just upgraded a CLI project to use angular 6+ Everything works just fine and the site shows data as excepted.. so no problems except for 1 small issue... 我刚刚升级了CLI项目以使用angular 6+,一切正常,并且站点显示例外数据。..因此,除了1个小问题之外,没有任何问题。

The 'this' context of type 'Observable' is not assignable to method's 'this' of type 'Observable<[Category, ProductList]>'. 类型'Observable'的'this'上下文不能分配给类型'Observable <[Category,ProductList]>'的方法'this'。

getStartpageCategoryWithProducts(startpagePosition, pageSize ?, page ?): Promise < [Category, ProductList] > {
  let params = new HttpParams();
  if(pageSize) { params = params.append('pageSize', pageSize); }
    if(page) { params = params.append('page', page); }
    const options = {
    params
  };
  const url = 'catalog/categories/startpagePosition/' + startpagePosition;
  return this.http.get(url, options).pipe(
    map(res => [res['category'], this.extractData(res['searchResult'])]),
    catchError((err) => this.handleError(err))
  ).toPromise<[Category, ProductList]>();
}

I think the problem is .get.map is not giving you an Observable<[Category, ProductList]> but just a plain Observable, you would be fine if you just remove the typing in toPromise 我认为问题是.get.map不是给您一个Observable <[Category,ProductList]>而是一个普通的Observable,如果您只删除toPromise中的输入,就可以了

getStartpageCategoryWithProducts(startpagePosition, pageSize ?, page ?): Promise {
  let params = new HttpParams();
  if(pageSize) { params = params.append('pageSize', pageSize); }
    if(page) { params = params.append('page', page); }
    const options = {
    params
  };
  const url = 'catalog/categories/startpagePosition/' + startpagePosition;
  return this.http.get(url, options).pipe(
    map(res => [res['category'], this.extractData(res['searchResult'])]),
    catchError((err) => this.handleError(err))
  ).toPromise();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM