我有错误:
TS2339:“订阅”类型上不存在属性“管道”
在标有“ HERE”的行下
import { Injectable } from '@angular/core';
import { HttpClient, HttpParams } from '@angular/common/http';
import { Observable } from 'rxjs';
import { Source } from '../model/source';
import { map } from 'rxjs/operators';
import { Entry } from '../model/entry';
@Injectable()
export class SourcesService {
private readonly API_URL = 'https://localhost:44384';
constructor(private http: HttpClient) { }
findEntries(
sourceId: number, filter = '', sortOrder = 'asc',
pageIndex = 0, pageSize = 3): Observable<Entry[]> {
return this.http.get(`${this.API_URL}/api/entries`, {
params: new HttpParams()
.set('sourceId', sourceId.toString())
.set('filter', filter)
.set('sortOrder', sortOrder)
.set('pageIndex', pageIndex.toString())
.set('pageSize', pageSize.toString()),
observe: 'response'
}).subscribe((res: any) => {
const counter = JSON.parse(res.headers.get('X-Pagination')).totalCount;
}).pipe( // <<<=========================================================== HERE
map((res: any) => {
res['playload'] = res;
return res['playload'];
})
);
}
环境:
Angular CLI: 7.0.3
Node: 10.13.0
OS: win32 x64
Angular: 7.0.1
答案 0 :(得分:1)
删除不需要的订阅。
您应该订阅还是使用rxjs
operators
,然后最后使用subscribe
。
import { Injectable } from '@angular/core';
import { HttpClient, HttpParams } from '@angular/common/http';
import { Observable } from 'rxjs';
import { Source } from '../model/source';
import { map } from 'rxjs/operators';
import { Entry } from '../model/entry';
@Injectable()
export class SourcesService {
private readonly API_URL = 'https://localhost:44384';
constructor(private http: HttpClient) { }
findEntries(
sourceId: number, filter = '', sortOrder = 'asc',
pageIndex = 0, pageSize = 3): Observable<Entry[]> {
return this.http.get(`${this.API_URL}/api/entries`, {
params: new HttpParams()
.set('sourceId', sourceId.toString())
.set('filter', filter)
.set('sortOrder', sortOrder)
.set('pageIndex', pageIndex.toString())
.set('pageSize', pageSize.toString()),
observe: 'response'
}).pipe(
map((res: any) => {
res['playload'] = res;
return res['playload'];
})
);
}