IT
[angular] route and parameter
로바아토
2018. 3. 19. 20:02
const appRoutes: Routes = [
{ path: '', component: HomeComponent },
{ path: 'users', component: UsersComponent },
{ path: 'users/:id/:name', component: UserComponent },
{ path: 'servers', component: ServersComponent }
];
we can see third one's path is little bit different.
:id, :name is for the parameter.
we can get the 'id' data like this.
this.user = {
id: this.route.snapshot.params['id'],
name: this.route.snapshot.params['name']
};
route can be used by this.
constructor(private route:ActivatedRoute) { }
we can use observable return for async like this
this.route.params.subscribe(
(params: Params) => {
this.user.id = params['id'];
this.user.name = params['name'];
}
);
until 124