我遇到了使用routerLink传递/获取参数的不可能性。
我有app.component.ts / html:
<header></header>
<router-outlet></router-outlet>
<footer class="flux-container">
...
<a routerLink="/info/1" routerLinkActive="active">Privacy Policy</a>
<a routerLink="/info/2" routerLinkActive="active">Terms & Conditions</a>
...
</footer>
和info.component.ts:
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
@Component({
selector: 'app-info',
templateUrl: './info.component.html',
styleUrls: ['./info.component.css']
})
export class InfoComponent implements OnInit {
order : number;
constructor(private activatedRoute: ActivatedRoute) { }
ngOnInit() {
this.order = this.activatedRoute.snapshot.params.id;
console.log('this.activatedRoute.snapshot.params ', this.activatedRoute.snapshot.params);
}
}
&#13;
routing.ts
{
path : 'info/:id',
canActivate : [AccountGuard, AppEnter],
pathMatch : 'full',
component : InfoComponent
},
&#13;
通过cliking / info / 1或/ info / 2
我无法获得this.activatedRoute.snapshot.params.id并仅使用刷新页面来使用它。只需简单的移动。
请帮助
答案 0 :(得分:1)
order$: Observable<string>;
this.order$ = this.activatedRoute.paramMap.pipe(map(resp => resp.get("id")));