Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get parameters passed by url in ionic 5

I have passed parameters in URL to my ionic application

http://localhost:8100/welcompage/overview?brand=bmw

I am using ActivatedRoute to retreive the data passed as parameters in the URL

   constructor(private route: ActivatedRoute) {
    }

    ngOnInit() {
        this.route.params.subscribe(params => {
             console.log(params['brand']);
        });
    }

the output is always "undefined" meanwhile there are parameters in the URL

like image 481
CoderTn Avatar asked Oct 19 '25 03:10

CoderTn


1 Answers

First method:

  let brand = this.route.snapshot.paramMap.get('brand');

Second method:

this.route.paramMap.subscribe(

  (data) => {

    console.log(data.brand)

  }

);

method1 or method2 fit your needs when You already define brand params on your route url/:brand. but if You use query params url?brand=value1&property2=vaule2... You could get query params data using method3:

method3:

this.route.queryParams
  .subscribe(params => {
    console.log(params); // { brand: "bmw" }
    let brand = params.brand;
    console.log(brand); // bmw
  }
);
like image 114
Zrelli Majdi Avatar answered Oct 20 '25 16:10

Zrelli Majdi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!