NVM 0.31.0: npm 3.10.3: Node.js 6.6.0Angular 2 Routing - Routing-Parameter erhalten - Typoskript
Von login.component.ts
gotoProfile(id:number):void {
let link = ['/profile'];
console.log("Routing to /profile/"+id);
this.router.navigate(link, id);
}
Console:
Routing to /profile/1
Von profile.component.ts
import { Router, ActivatedRoute, Params } from '@angular/router';
constructor(private route:ActivatedRoute,
private router:Router,
private profileService:ProfileService) {
}
ngOnInit():void {
this.route.params
.subscribe(params => {
let id = params['id'];
console.log("id " + id);
this.profileService.getProfileById(id)
.subscribe(
p => this.model = p,
err => this.handleError(err),
() => console.log("getting profile complete")
);
});
Von C onsole:
id undefined
Von app.routing.ts
path: 'profile/:id',
component: ProfileComponent
Wenn ich diese dann geben Sie im Browser: http://localhost:3000/profile/1 Console:
id 1
Also, was soll ich hier fehlt :)
Dieses Beispiel verwendet ein Versprechen, wo ich Observable verwende. Ich bin neu in eckigen und ich habe das Hero-Tutorial durchlaufen. – klind