s

angular read query params from url edit button Edit

author
Murugan Andezuthu Dharmaratnam | calendar 03 September 2020 | 2565

there are multiple options to read query params in angular 2 application. In your angular application, you can use angular or javascript to read query params. check the code below to read query params using ActivatedRoute.

Sample Code Using ActivatedRoute

in the controller inject ActivatedRoute

constructor(public route:ActivatedRoute)

const id = this.route.snapshot.params["id"];
console.log("id = "   id2);
             
                    

option 2 would be to use javascript location.href

Subtitle with Paragraph

const id = window.location.href.split('=')[1];
console.log(id);
               
                    

in the above code only id is being read. please check this link to read article about reading query params using javascript