2017-07-29 85 views
2

英雄detail.component.ts屬性'paramMap'在類型'ActivatedRoute'上不存在。/node_modules/@角/路由器/索引「」沒有出口成員 'ParamMap'

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'.

回答

4

ParamMap4.0.0-rc.6版本被引入。請確保您有-least角4版本。

+0

什麼是角2當量? – Ring

+0

@Ring你爲什麼想要後退版本? –

0

此問題可能是角版本conflict.your版本可能是版本低於4.0.0-rc.6 這種方法可能有助於解決問題往昔

向參數發送組件添加波紋管線:

this.router.navigate(['profile'],{queryParams:{authdata:email}});

添加波紋管線到參數接收組件:

this.route.snapshot.queryParams [ '的authData'];

波紋管線到Routermodule: { 路徑: '輪廓', 組分:ProfileComponent }

+0

需要一些格式 – Billa

相關問題