rxjs6

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

不想你离开。 提交于 2019-11-29 09:28:23
问题 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

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

本秂侑毒 提交于 2019-11-29 01:23:48
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.navigateByUrl('/login'); return Observable.of(); } else { return Observable.throw(error); } }); }

Angular - “has no exported member 'Observable'”

孤街醉人 提交于 2019-11-28 15:15:34
Typescript code: import { Injectable } from '@angular/core'; import { Observable } from 'rxjs/Observable'; import { of } from 'rxjs/observable/of'; import { Hero } from './hero'; import { HEROES } from './mock-heroes'; @Injectable({ providedIn: 'root' }) export class HeroService { constructor() { } getHeroes(): Observable<Hero[]> { return of(HEROES); } } error info: error TS2307: Cannot find module 'rxjs-compat/Observable'. node_modules/rxjs/observable/of.d.ts(1,15): error TS2307: Cannot find module 'rxjs-compat/observable/of'. src/app/hero.service.ts(2,10): error TS2305: Module '"F:/angular

How to get “Observable.of([]);” to work?

坚强是说给别人听的谎言 提交于 2019-11-28 13:34:44
What is the correct expression and import for Observable.of([]); . import { of } from 'rxjs'; does not work for me. Since RxJS 6 you should import all "creation" observables directly from 'rxjs' (assuming you have path maps set when bundling your app). More detailed explanation: https://github.com/ReactiveX/rxjs/blob/master/MIGRATION.md#import-paths import { of } from 'rxjs'; of(1).subscribe(console.log); See demo: https://stackblitz.com/edit/typescript-e3lxkb?file=index.ts No need to use Observable.of(T) Instead you can use the below syntax in the rxjs 6.3.3 return new Observable<AppUser>();

Could not use Observable.of in RxJs 6 and Angular 6

那年仲夏 提交于 2019-11-28 05:38:48
import { Observable, of } from "rxjs"; // And if I try to return like this return Observable.of(this.purposes); I am getting an error stating, Property 'of' does not exist on type 'typeof Observable' Looks like cartant's comment is correct, the RxJS upgrade guide doesn't cover that method specifically but does say "Classes that operate on observables have been replaced by functions" Which seems to mean all or most of those class methods like .of, .throw etc. have been replaced by a function So instead of import { Observable, of } from "rxjs"; Observable.of(this.purposes); do import { of } from

error TS2339: Property 'takeUntil' does not exist on type 'Observable<Foo>' and other rxjs v.6 errors

可紊 提交于 2019-11-27 14:59:52
问题 I just recently updated A LOT of packages in my angular project. Old package.json: { "name": "data-jitsu", "version": "0.0.0", "license": "MIT", "scripts": { "ng": "ng", "start": "ng serve", "build": "ng build", "test": "ng test", "lint": "ng lint", "e2e": "ng e2e" }, "private": true, "dependencies": { "@angular/animations": "^5.2.10", "@angular/cdk": "^5.2.5", "@angular/common": "5.2.7", "@angular/compiler": "5.2.7", "@angular/core": "5.2.7", "@angular/forms": "5.2.7", "@angular/http": "5.2

Angular - “has no exported member 'Observable'”

£可爱£侵袭症+ 提交于 2019-11-27 09:06:59
问题 Typescript code: import { Injectable } from '@angular/core'; import { Observable } from 'rxjs/Observable'; import { of } from 'rxjs/observable/of'; import { Hero } from './hero'; import { HEROES } from './mock-heroes'; @Injectable({ providedIn: 'root' }) export class HeroService { constructor() { } getHeroes(): Observable<Hero[]> { return of(HEROES); } } error info: error TS2307: Cannot find module 'rxjs-compat/Observable'. node_modules/rxjs/observable/of.d.ts(1,15): error TS2307: Cannot find

How to get “Observable.of([]);” to work?

Deadly 提交于 2019-11-27 07:46:42
问题 What is the correct expression and import for Observable.of([]); . import { of } from 'rxjs'; does not work for me. 回答1: Since RxJS 6 you should import all "creation" observables directly from 'rxjs' (assuming you have path maps set when bundling your app). More detailed explanation: https://github.com/ReactiveX/rxjs/blob/master/MIGRATION.md#import-paths import { of } from 'rxjs'; of(1).subscribe(console.log); See demo: https://stackblitz.com/edit/typescript-e3lxkb?file=index.ts 回答2: No need