angular - Angular2 Routerlink: add query parameters -


how can add query parameters routerlink?

@routeconfig {    {path: '/search',   name: 'search', component: searchcmp} }   

let' want route /search?q=asdf,

<a [routerlink]= " [ '/search' , {q= 'asdf'}] ">link 1</a> 

this resolves /search .

is there way add query parameters without using:

this.router.navigate( ['search', { q: 'asdf'}]); 

or

<a href="/search?a=asdf"> link 2 </a> 

?

if u need /search?q=asdf can use:

@routeconfig {    {path: '/search',   name: 'search', component: searchcmp} }  //and generate router links use:  <a [routerlink]="['/search']" [queryparams]="{q:'asdf'}"></a> 

this generate href tag <a href="/search" on clicking anchor tag lead url /search?q=asdf. [queryparams] let add query params "?", otherwise appended ";". can parameter in searchcmp using:

constructor(private _routeparams: routeparams) {    var queryparam = this._routeparams.get('q'); } 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -