我试图从 url 栏中获取路线和查询。下面的代码来自 CodeWithMosh 的教程。我在 combineLatest 方法中遇到编译错误。
错误如下:
(属性) paramMap: Observable 类型的参数'{ paramMap: Observable; queryParamMap:可观察的;}' 不可分配给“ObservableInput”类型的参数。
对象字面量只能指定已知属性,而“ObservableInput”类型中不存在“paramMap”
我是角度的新手,我不确定错误是什么意思,我已经尝试遵循这个堆栈溢出答案,但我仍然得到错误。谢谢你。
完整代码如下:
import { ActivatedRoute } from '@angular/router';
import { GithubFollowersService } from './../services/github-followers.service';
import { Component, OnInit } from '@angular/core';
import 'rxjs/add/Observable/combineLatest';
import { Observable } from 'rxjs/internal/Observable';
import { combineLatest } from 'rxjs';
@Component({
selector: 'github-followers',
templateUrl: './github-followers.component.html',
styleUrls: ['./github-followers.component.css']
})
export class GithubFollowersComponent implements OnInit {
followers : any[];
constructor(
private route: ActivatedRoute,
private service : GithubFollowersService) { }
ngOnInit() {
const paramMap = this.route.paramMap;
const queryParamMap = this.route.queryParamMap;
combineLatest({
paramMap, // error here
queryParamMap
})
.subscribe(combined => {
let id = combined[0].get('id');//the 0 means the 1st 1 which is paramMap from above
let page = combined[1].get('page');
this.service.getAll().subscribe(followers => this.followers = followers);
});
}
}