Observable.combineLatest不是函数 [英] Observable.combineLatest is not a function

查看:350
本文介绍了Observable.combineLatest不是函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个主页页面,用户在其中单击与我联系,将其重定向到联系页面:

I have a Home page, somewhere in it the user clicks on Contact me to be redirected to the Contact page:

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();    
  }
}

通过点击首页上的与我联系,我收到此错误:

By clicking on Contact me on Home, I get this error:

ContactComponent_Host.ngfactory.js? [sm]:1 ERROR TypeError: Observable_1.Observable.combineLatest is not a function

请帮助我找出问题所在.

Please help me find out the problem.

推荐答案

在角度6中,

您只需要:

import {combineLatest} from "rxjs/index";

并替换

Observable.combineLatest(...)

作者

combineLastest(...)

这篇关于Observable.combineLatest不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆