小编su1*_*212的帖子

无法读取未定义的属性“管道” - Angular 6

组件.ts

// Component containing function
Public myData(){
    this.myService.getData()
        .pipe(
            take(1),
            catchError((err: any) => {
                this.myRows = [];
                return throwError(err);
            }),
            finalize(() => {
                console.log('In Finally');
            })
        )
        .subscribe((rows) => {
            this.myRows = rows;
            // Do something
        });
}
Run Code Online (Sandbox Code Playgroud)

myService.ts

// Service Call
public getData(): Observable < customer[] > {
    const url = 'some url';
    return this.http.get(url).pipe(
        map(this.checkForError),
        catchError((err: HttpErrorResponse) => {
            return throwError(err);
        }),
        map(this.myJson),
        share()
    );
}
Run Code Online (Sandbox Code Playgroud)

规格

    // Test Case
    it('should test', () => {
        let test = …
Run Code Online (Sandbox Code Playgroud)

unit-testing jasmine karma-jasmine angular angular6

4
推荐指数
1
解决办法
2万
查看次数

RxJS 管道 Finalize 操作符没有被调用

import {
    Observable,
    BehaviorSubject
} from 'rxjs';
import {
    finalize,
    share
} from 'rxjs/operators'

export class someComponent() {

    public count$ = new BehaviorSubject < any > (0);

    public constructor() {
        this.shareResponse()
            .pipe(
                finalize(() => {
                    console.log('finalize called');
                }))
            .subscribe((event: any) => {
                // Do something
            });
    }
    public shareResponse(): Observable < any > {
        return this.count$.pipe(share());
    }
    public countChanged(event) {
        this.count$.next(event);
    }
}
Run Code Online (Sandbox Code Playgroud)

HTML:

    <some-tag(countChanged) = (countChanged($event)) > < /some-tag>
Run Code Online (Sandbox Code Playgroud)

rxjs angular6 angular7

2
推荐指数
1
解决办法
1042
查看次数