How to combine Observables by combineLatest. combineLatest is not defined
I am using angular js 7.I want to marge tow query string parameter but when I write the obserable.combinelaste([]) then it will give en error.
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { Observable, of, observable } from 'rxjs'
import { combineLatest } from 'rxjs/observable/combineLatest';
@Component({
selector: 'app-githubfollowers',
templateUrl: './githubfollowers.component.html',
styleUrls: ['./githubfollowers.component.css']
})
export class GithubfollowersComponent implements OnInit {
constructor(private rout:ActivatedRoute ) { }
ngOnInit() {
Observable.combineLatest([ this.rout.paramMap,
this.rout.queryParamMap
]);
this.rout.paramMap.subscribe(prams=>{
});
this.rout.queryParamMap.subscribe(prams=>{
});
}
}
You import is wrong. You used the import for RXJS v5.
For RxJS v6+, you should use this import :
import { combineLatest } from 'rxjs';
To solve the following error message :
ngOnInit() { Observable.combineLatest([ this.rout.paramMap, this.rout.queryParamMap ]); Property 'combineLatest' does not exist on type 'typeof Observable
You can use combineLatest
like this :
combineLatest(this.rout.paramMap, this.rout.queryParamMap)
And you probably have to spend some time to read how to use it: https://www.learnrxjs.io/operators/combination/combinelatest.html
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.