gpt4 book ai didi

angular - Observable.combineLatest 不是一个函数

转载 作者:行者123 更新时间:2023-12-02 10:18:36 24 4
gpt4 key购买 nike

我有一个主页页面,用户在其中点击联系我即可重定向到联系页面:

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

请帮我找出问题所在。

最佳答案

Angular 为 6,

你只需要:

import {combineLatest} from "rxjs/index";

并替换

Observable.combineLatest(...)

combineLastest(...)

关于angular - Observable.combineLatest 不是一个函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51369335/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com