angular - How to get QueryParam in factory provider (Angular4) -
i want provide constant in application basing on queryparam url.
localhost:4200?flag=true
in module providers added
{ provide: flag, usefactory: flagfactory, deps: [...] }
so interested if there way how without parsing url manually
function flagfactory() { return location.search.includes('flag'); }
what using angular router?
the router tracks query parameters, should available on initial route '/'
your root component have route allows this
constructor(private route: activatedroute) {} ngoninit() { this.sub = this.route.params.subscribe(params => { this.flag = params['flag']; }); }
Comments
Post a Comment