gpt4 book ai didi

angular - 类型 'paramMap' 上不存在属性 'ActivatedRoute' ./node_modules/@angular/router/index "' has no exported member ' ParamMap'

转载 作者:行者123 更新时间:2023-12-02 17:14:15 24 4
gpt4 key购买 nike

英雄细节.component.ts

import { Component, Input, OnInit } from '@angular/core';
import 'rxjs/add/operator/switchMap';
import { ActivatedRoute} from '@angular/router';
import { ParamMap } from '@angular/router';
import { Location } from '@angular/common';
import { Hero } from '../hero';
import { HeroService } from '../services/hero.service';

@Component({
selector: 'app-hero-detail',
templateUrl: './hero-detail.component.html',
styleUrls: ['./hero-detail.component.css']
})
export class HeroDetailComponent implements OnInit {

@Input() hero: Hero;

constructor(
private heroService: HeroService,
private route: ActivatedRoute,
private location: Location
) { }

ngOnInit(): void {
this.route.paramMap
.switchMap((params: ParamMap) => this.heroService.getHero(+params.get('id')))
.subscribe(hero => this.hero = hero);
}

goBack(): void {
this.location.back();
}

}

Error: 1> node_modules/@angular/router/index"' has no exported member 'ParamMap'.

2> Property 'paramMap' does not exist on type 'ActivatedRoute'.

最佳答案

ParamMap已在4.0.0-rc.6版本中引入。确保您至少有 Angular 4 版本。

关于angular - 类型 'paramMap' 上不存在属性 'ActivatedRoute' ./node_modules/@angular/router/index "' has no exported member ' ParamMap',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45388656/

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