![](/img/trans.png)
[英]RXJS 6.3.3 Ionic TypeError: Observable.combineLatest is not a function
[英]Observable.combineLatest is not a function
我有一個主頁 ,用戶點擊它的某個地方聯系我以重定向到聯系頁面:
home.component.html
<div>
<a routerLink="/contact" [queryParams]="sendOBj">Contact me</a>
</div>
home.component.ts:
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '../../../node_modules/@angular/router';
import { FollowersService } from '../followers.service';
@Component({
selector: 'app-home',
templateUrl: './home.component.html',
styleUrls: ['./home.component.css']
})
export class HomeComponent implements OnInit {
myfollowers: any[];
sendOBj: {id: any, name: any};
constructor(private followers: FollowersService, private route: ActivatedRoute) { }
ngOnInit() {
this.myfollowers = this.followers.getFollowers();
this.sendOBj = {id: this.myfollowers[0].id, name: this.myfollowers[0].name };
}
}
contact.component.ts:
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '../../../node_modules/@angular/router';
import { Observable } from '../../../node_modules/rxjs/Observable';
import 'rxjs/observable/combineLatest';
@Component({
selector: 'app-contact',
templateUrl: './contact.component.html',
styleUrls: ['./contact.component.css']
})
export class ContactComponent implements OnInit {
constructor( private route: ActivatedRoute) { }
ngOnInit() {
Observable.combineLatest([
this.route.queryParamMap
])
.subscribe(
combined=>{
let id = combined[1].get('id');
console.log('id', id);
}
);
this.route.queryParamMap.subscribe();
}
}
通過點擊在家 聯系我 ,我收到此錯誤:
ContactComponent_Host.ngfactory.js? [sm]:1 ERROR TypeError: Observable_1.Observable.combineLatest is not a function
請幫我找出問題所在。
角度6,
您只需要:
import {combineLatest} from "rxjs/index";
並替換
Observable.combineLatest(...)
通過
combineLastest(...)
我這樣解決了問題:
我首先升級到Angular 6,然后像這樣修改了contact.component.ts :
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '../../../node_modules/@angular/router';
import { combineLatest } from 'rxjs/operators';
import { CombineLatestSubscriber } from '../../../node_modules/rxjs/operators/combineLatest';
@Component({
selector: 'app-contact',
templateUrl: './contact.component.html',
styleUrls: ['./contact.component.css']
})
export class ContactComponent implements OnInit {
constructor( private route: ActivatedRoute) { }
ngOnInit() {
this.route.paramMap.subscribe();
this.route.queryParamMap.subscribe(
user=>{
console.log('username: ', user.get('name'));
console.log('user id', user.get('id'));
}
);
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.