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
'IT' 카테고리의 다른 글
[angular] retrieve the data as number (0) | 2018.03.21 |
---|---|
[angular] QueryParameters and Fragments (0) | 2018.03.21 |
[angular] Router navigate relatively (0) | 2018.03.19 |
[angular] Router Navigation programmatically (0) | 2018.03.19 |
[angular] routerLinkActive and routerLinkOptions (0) | 2018.03.19 |