rxjs6

TypeScript module Augmentation

随声附和 提交于 2019-12-01 05:45:27
I have extension for observable. It was working perfectly fine but now I've updated to angular 6 with typescript 2.7.2. import { Observable } from 'rxjs/Observable'; import { BaseComponent } from './base-component'; import { Subscription } from 'rxjs/Subscription'; import { Subscribable } from 'rxjs'; declare module 'rxjs/Observable' { export interface Observable<T> { safeSubscribe<T>(this: Observable<T>, component: BaseComponent, next?: (value: T) => void, error?: (error: T) => void, complete?: () => void): Subscription; } } export function safeSubscribe<T>(this: Observable<T>, component:

TypeScript module Augmentation

心不动则不痛 提交于 2019-12-01 04:06:45
问题 I have extension for observable. It was working perfectly fine but now I've updated to angular 6 with typescript 2.7.2. import { Observable } from 'rxjs/Observable'; import { BaseComponent } from './base-component'; import { Subscription } from 'rxjs/Subscription'; import { Subscribable } from 'rxjs'; declare module 'rxjs/Observable' { export interface Observable<T> { safeSubscribe<T>(this: Observable<T>, component: BaseComponent, next?: (value: T) => void, error?: (error: T) => void,

Using shareReplay(1) in Angular - still invokes http request?

邮差的信 提交于 2019-11-30 14:43:32
I've created a demo ( ng-run ) where I have a button which invokes an Http request. When the button is clicked, I invoke this method : public getData(){ this._jokeService.getData().subscribe(); } Which in turn invokes this ( from a service) : public getData() { return this.http.get(API_ENDPOINT).pipe(shareReplay(1)) } The problem is that on every click - I still see a new http request initiated : Question: Why doesn't shareReplay keeps the last value of the response? How can I make my code to invoke the http only once and keep that value for future subscriptions ? Edit: solution is here If you

How do I mock RxJs 6 timer?

折月煮酒 提交于 2019-11-30 13:40:15
We've recently updated from Angular 5 to Angular 6, and with it RxJs 6. As part of the migration, the timer usage has changed from: Observable.timer() to timer() There are a number of places in our tests where we mock timer observables with the following pattern. let timerObserver: Observer<any>; beforeEach(() => { spyOn(Observable, 'timer').and.returnValue(Observable.create( ((observer: Observer<any>) => { timerObserver = observer; }) )); }); it(`should not have any notifications by default`, () => { timerObserver.next(''); ... }); Does anybody know how to migrate this pattern across? Edit: I

Angular : how to call finally() with RXJS 6

痴心易碎 提交于 2019-11-30 11:04:26
I was using RXJS 5, now as I upgraded it to 6, I am facing some problems. Previously I was able to use catch and finally but as per update catch is replaced with catchError (with in the pipe) now how to use finally? Also I have some questions : Do I need to change throw->throwError (in below code Observable.throw(err);) import { Observable, Subject, EMPTY, throwError } from "rxjs"; import { catchError } from 'rxjs/operators'; return next.handle(clonedreq).pipe( catchError((err: HttpErrorResponse) => { if ((err.status == 400) || (err.status == 401)) { this.interceptorRedirectService

Error: Can't resolve 'rxjs/add/operator/map'

做~自己de王妃 提交于 2019-11-30 08:32:58
This is app.module.ts I have tried to done the Import of map in different project and it worked fine, but in this project it's not working. import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; import {HttpModule} from '@angular/http'; import { AppComponent } from './app.component'; import { PagesComponent } from './pages/pages.component'; @NgModule({ declarations: [ AppComponent, PagesComponent ], imports: [ BrowserModule, HttpModule ], providers: [], bootstrap: [AppComponent] }) export class AppModule { } app.component.ts import { Component }

Angular 6: Property 'catch' does not exist on type 'Observable<Response>'?

百般思念 提交于 2019-11-30 07:09:44
问题 I am upgrading my app to Angular 6 . I am upgrading from Angular 4 , but the code below is causing errors in Angular 6, where it worked fine in Angular 4. The errors I am getting: Property 'of' does not exist on type 'typeof Observable' Error: Property 'catch' does not exist on type 'Observable' How should I resolve these errors? private authInterceptor(observable: Observable<Response>): Observable<Response> { return observable.catch((error, source) => { if (error.status == 401) { this.router

Angular 6 router.events.filter 'filter' does not exist on type 'Observable<Event>'

拜拜、爱过 提交于 2019-11-30 04:19:56
I have finished to update my App to Angular 6 (it was in 5.2 version). I got an error syntax in : import { Router, ActivatedRoute, NavigationEnd } from '@angular/router'; import { filter } from 'rxjs/operators'; ... constructor(private router: Router) {} this.router.events.filter (event => event instanceof NavigationEnd).subscribe((res) => { // DO something }); error TS2339: Property 'filter' does not exist on type 'Observable'. what's the right syntax in Angular 6 ? thanks Lansana Camara This is how to filter router events with Angular 6+ and latest RxJS: import { Component, OnInit } from '

RXJS 6: new version of HttpInterceptor

笑着哭i 提交于 2019-11-29 12:39:56
问题 I am in the process of adding rxjs_compat to my project in order to move to v6 of libraries. However the existing HttpInterceptor for global error handling no longer compiles. Not sure where to go with it. Tried all sorts. Getting type mismatches with everything tried. import { Injectable } from "@angular/core"; import { HttpEvent, HttpInterceptor, HttpHandler, HttpRequest, HttpResponse, HttpErrorResponse } from "@angular/common/http"; import { Observable, of, empty } from "rxjs"; import {

Error: Can't resolve 'rxjs/add/operator/map'

被刻印的时光 ゝ 提交于 2019-11-29 12:02:32
问题 This is app.module.ts I have tried to done the Import of map in different project and it worked fine, but in this project it's not working. import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; import {HttpModule} from '@angular/http'; import { AppComponent } from './app.component'; import { PagesComponent } from './pages/pages.component'; @NgModule({ declarations: [ AppComponent, PagesComponent ], imports: [ BrowserModule, HttpModule ],