IT

[angular] QueryParameters and Fragments

로바아토 2018. 3. 21. 11:23

set in html

<a
[routerLink]="['/servers', 5, 'edit']"
[queryParams]="{allowEdit: '1'}"
fragment="loading"
href="#"
class="list-group-item"
*ngFor="let server of servers">
{{ server.name }}
</a>



set in ts code

this.router.navigate(
['/servers', id, 'edit'],
{queryParams: {allowEdit: '1'},
fragment:'loading'});




retrieve query params

console.log(this.route.snapshot.queryParams);
console.log(this.route.snapshot.fragment);
this.route.queryParams.subscribe(
(params:Params) => {
console.log(params['id']);
}
);
this.route.fragment.subscribe(
(frag:string) => {
console.log(frag);
}
);