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

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -