rxjs6

combineLatest deprecated in favor of static combineLatest

独自空忆成欢 提交于 2019-12-04 02:59:19
问题 After running the rxjs migration tool using rxjs-5-to-6-migrate -p src/tsconfig.app.json I'm now getting a linting error: combineLatest is deprecated: Deprecated in favor of static combineLatest. Here is my code before running the migration command: this.store.combineLatest( this.store.select(lang.getCurrent), this.store.select(lang.getCurrentLocale) ).subscribe(([state, currentLang, locale]) => { this._language = session.language === currentLang ? '' : currentLang; this._locale = session

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

巧了我就是萌 提交于 2019-12-03 19:07:02
问题 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 回答1: This is how

mergeMap does not exist on type observable

我怕爱的太早我们不能终老 提交于 2019-12-03 15:44:55
I am trying to use mergeMap in rxjs6 and i am getting this error: Property 'mergeMap' does not exist on type 'Observable<{}>' I have tried import 'rxjs/add/operator/mergeMap'; and it is not working. What am i doing wrong? import {from, Observable} from 'rxjs'; export class Test { public doSomething(): Observable<any> { return from(...).mergeMap(); } } That's correct, the "patch" style of operators has been removed since RxJS 6. You should better update your code to use only "pipeable" operators or install rxjs-compat package that provides backwards compatibility with RxJS 5. For more detailed

Angular/RxJS 6: How to prevent duplicate HTTP requests?

随声附和 提交于 2019-12-03 11:16:55
Currently have a scenario where a method within a shared service is used by multiple components. This method makes an HTTP call to an endpoint that will always have the same response and returns an Observable. Is it possible to share the first response with all subscribers to prevent duplicate HTTP requests? Below is a simplified version of the scenario described above: class SharedService { constructor(private http: HttpClient) {} getSomeData(): Observable<any> { return this.http.get<any>('some/endpoint'); } } class Component1 { constructor(private sharedService: SharedService) { this

Loop array and return data for each id in Observable

两盒软妹~` 提交于 2019-12-03 08:57:56
Using RxJS v6 is challenging to retrieve data from sub collection for every item in the loop. There is no way to iterate throw array that is retrieved from HTTP call. Merge map does it only for single item where there is a requirement to do it on all array items. I've been stuck on this for 3 days. I've tried everything. Problem is that new pipe syntax while provides you with neat way to organise code there is no easy way to loop throw collection of data. It is impossible to use map javascript function as it is outside observable and items returned are undefined. On internet I could only find

How to detect rxjs related memory leaks in Angular apps

人走茶凉 提交于 2019-12-03 05:46:58
问题 Is there any tool or technique to detect "left behind" or "currently alive" observables, subscriptions. Just recently discovered a pretty nasty memory leak where components were kept alive due to missing "unsubscribe" calls. I read about "takeUntil" approach which seems pretty good. https://stackoverflow.com/a/41177163/2050306 However I'm still wondering is there any tool (browser extension etc.) for that. Augury does not cover this area as far as I know. All input is greatly appreciated. 回答1

Angular 6 View is not updated after changing a variable within subscribe

浪尽此生 提交于 2019-12-03 01:33:52
Why is the view not being updated when a variable changes within a subscribe? I have this code: example.component.ts testVariable: string; ngOnInit() { this.testVariable = 'foo'; this.someService.someObservable.subscribe( () => console.log('success'), (error) => console.log('error', error), () => { this.testVariable += '-bar'; console.log('completed', this.testVariable); // prints: foo-Hello-bar } ); this.testVariable += '-Hello'; } example.component.html {{testVariable}} But the view displays: foo-Hello . Why won't it display: foo-Hello-bar ? If I call ChangeDetectorRef.detectChanges() within

Error: Property 'map' does not exist on type 'Observable'

人盡茶涼 提交于 2019-12-02 12:23:51
After I updated angular/cli, I got an error: error TS2339: Property 'map' does not exist on type 'Observable<Response>' I tried every possible solution from Property 'map' does not exist on type 'Observable<Response>' but still the error exists. Its easy to post an answer when you provide your code instead of a screenshot. Anyhow , you have to pipe it: getUsers() { return this._http.get(this.baseUrl+'/show-users', this.options) .pipe( map((response:Response)=>response.json()) ); Remember to import map like this: import { map } from 'rxjs/operators'; For the latest Version of rxjs we need to

combineLatest deprecated in favor of static combineLatest

懵懂的女人 提交于 2019-12-01 14:56:37
After running the rxjs migration tool using rxjs-5-to-6-migrate -p src/tsconfig.app.json I'm now getting a linting error: combineLatest is deprecated: Deprecated in favor of static combineLatest. Here is my code before running the migration command: this.store.combineLatest( this.store.select(lang.getCurrent), this.store.select(lang.getCurrentLocale) ).subscribe(([state, currentLang, locale]) => { this._language = session.language === currentLang ? '' : currentLang; this._locale = session.locale === locale ? '' : locale; }); My code after running the migration command: (currently presenting a

Angular 6 : where getting error module “rxjs/add/operator/map” and another error 'map' does not exist on type 'Observable<Response>'

孤者浪人 提交于 2019-12-01 14:52:43
I am using Angular 6 where I am getting two errors - ERROR in ./src/app/app/img/img.service.ts Module not found: Error: Can't resolve 'rxjs/add/operator/map' in '/Users/user/Projects/A4/imageSearch/src/app/app/img' ERROR in src/app/app/img/img.service.ts(21,9): error TS2339: Property 'map' does not exist on type 'Observable'. I faced similar problem with rxjs map operator. Currently I'm using Angular 6. To know which version you are using: ng --version or ng -v If you are also using angular 6, then please checkout https://www.academind.com/learn/javascript/rxjs-6-what-changed/ Different