rxjs6

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

心不动则不痛 提交于 2019-12-17 17:53:23
问题 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' 回答1: 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

unable to compile a code when converted into a function

北战南征 提交于 2019-12-14 03:05:15
问题 I have the following piece of code which works correctly. public createData(data:Data):Observable<any>{ console.log('contacting server at '+this.API_URL +this.NEW_DATA_URL +" with data "+data+ " with httpOptions "+httpOptions.withCredentials + ","+httpOptions.headers ); let newData = new Data(data) let body = JSON.stringify(newQuestion); //I WANT TO MOVE THE CODE BELOW INTO A FUNCTION BUT AM GETTING COMPILATION ERROR this.loaderService.show(); return this.http.post(this.NEW_QUESTION_URL,body

RsJX 'Map' operator is not working in Angular 6

∥☆過路亽.° 提交于 2019-12-13 18:15:47
问题 I'm trying to use map operator from RxJS but it throws an error saying Property 'map' does not exist on type 'Observable'. Here is the code import { Injectable } from "@angular/core"; import { Http } from "@angular/http"; import "rxjs/add/operator/map"; @Injectable() export class DataService { constructor(public http: Http) {} getData() { return this.http .get("https://jsonplaceholder.typicode.com/users") .map(res => res.json()); } } 回答1: For first Http is deprecated in higher versions than

Rxjs import issues in Angular 6

非 Y 不嫁゛ 提交于 2019-12-13 17:57:25
问题 I am facing some weird issues while working with Angular 6 and Rxjs 6. When I import as below Import { forkJoin } from 'rxjs/internal/observable/forkJoin'; I am getting issue as but when I use import as import { forkJoin } from 'rxjs/'; it works perfectly. I used the same method to merge operator but when i used import as import { merge } from 'rxjs/'; but it thrown error as above and it works fine if i use import { merge } from 'rxjs/internal/observable/merge'; Could someone point out where

How do I use catchError() and still return a typed Observable with rxJs 6.0?

↘锁芯ラ 提交于 2019-12-13 11:57:47
问题 cdSo I'm trying to migrate some of my Angular 5 code to 6, and I understand most of the changes required for rxjs to work using the .pipe() operator. It works as you would expect for 'pipable' operations. However, the behavior of catchError() is different than the .catch() operator. Prior to rxjs 6 I used the .catch() operator to transform the error input into a a consistent error object that can then be caught in the `.subscribe(). getAlbums(): Observable<Album[]> { return this.httpClient

After getting the response from post api call , an error is thrown => .pipe is not a function

只愿长相守 提交于 2019-12-13 07:57:29
问题 I am making an api call and expecting a response from it which can be passed to 2nd api call but I am getting an error ERROR TypeError: this.helperService.getPointIdbyTags(...)[0].pipe is not a function on line .pipe(switchMap((resarray:any)=>{ TS code someFunction(floor){ floor.entities.forEach(element => { let desiredTempForZone; this.getCurrentValue(element.name).subscribe((des) => { currentTempForZone = des }); console.log(currentTempForZone); }) } getCurrentValue(eleName){ let roomObj =

angular component is retaining old value maybe because the observable is resending past data

风格不统一 提交于 2019-12-13 03:31:33
问题 In the following pics, I visit a component, which on selecting a value from a drop down shows some values. If now, i click on home page and then revisit the component, then i still see the old values. Why is the component retaining old values? on start after selecting from drop box, the values gets populated now visit home page on revisiting, still seeing old values The html of the component is <div id="practice-questions-list-top-level-div"> <div id="practice-questions-tags-form-container" >

Do I need to `complete()` takeUntil Subject inside ngOnDestroy?

懵懂的女人 提交于 2019-12-13 02:52:21
问题 To avoid Observable memory leaks inside Components, I am using takeUntil() operator before subscribing to Observable. I write something like this inside my components: private unsubscribe$ = new Subject(); ngOnInit(): void { this.http .get('test') .pipe(takeUntil(this.unsubscribe$)) .subscribe((x) => console.log(x)); } ngOnDestroy(): void { this.unsubscribe$.next(); this.unsubscribe$.complete(); // <--- ?? } Finally my question is following: Do I need to write this.unsubscribe$.complete(); or

Property 'catchError' does not exist on type 'Observable<HttpEvent<any>>'

时光怂恿深爱的人放手 提交于 2019-12-12 15:20:28
问题 Went from angular 5 to 6(using angular 6 & rxjs 6), getting the following two errors in my linter. Anybody have any ideas, please and thank you. [ts] 'catchError' is declared but its value is never read. [ts] Property 'catchError' does not exist on type 'Observable<HttpEvent<any>>'. import { Injectable, Injector } from '@angular/core'; import { HttpEvent, HttpInterceptor, HttpHandler, HttpRequest } from '@angular/common/http'; import { catchError } from 'rxjs/operators'; import { Observable }

How to properly chain rxjs 6 observables?

醉酒当歌 提交于 2019-12-12 08:57:53
问题 Any suggestions, how this can be rewritten in more promise-chaining style?: this.apiService.sendPutRequest('/api/users/activate', usrObj).pipe( map(() => { return this.apiService.sendGetRequest('/api/users/' + this.currentUserId).pipe( map(data => { return this.setActiveUser(data).pipe( map(() => { return this.apiService.sendGetRequest('api/tasks/user/' + this.currentUserId).pipe( map(tasks => { return this.taskService.setCurrentUserTasks(tasks); }) ); }) ); }) ); }) ); 回答1: You can use