作者:莫小刚002 | 来源:互联网 | 2022-12-10 14:44
我有一个主页,用户在其中单击“ 联系我”以将其重定向到“ 联系”页面:
home.component.html
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
请帮助我找出问题所在。
1> Wandrille..:
在角度6中
您只需:
import {combineLatest} from "rxjs/index";
并更换
Observable.combineLatest(...)
通过
combineLastest(...)