Answers for "angular get url param"

4

angular get url param

constructor(private activatedRoute: ActivatedRoute) {
  this.activatedRoute.queryParams.subscribe(params => {
        let date = params['startdate'];
        console.log(date); // Print the parameter to the console. 
    });
}
Posted by: Guest on November-25-2020
1

get url params angular

import { ActivatedRoute, Params } from '@angular/router';

@Component(...)
export class MyComponent implements OnInit {
   constructor (private activatedRoute: ActivatedRoute){}
   
   ngOnInit() {
    this.activatedRoute.params.subscribe((params: Params) => {
      if (params.myParam){
        // Do something
      }
    });
   }
}
Posted by: Guest on June-25-2020
1

angular get url params

import { ActivatedRoute } from "@angular/router";

//import ActivatedRoute in constructor()
private $route: ActivatedRoute

// in ngOnInit() call
//myvar is the variable where you want to store your param
this.$route.params.forEach(param =>
	this.myvar = param['whatever your param name is']
);
Posted by: Guest on March-19-2020
0

angular url parameter

// example url: details?id=2

constructor(private activatedRoute: ActivatedRoute) {
  this.activatedRoute.queryParams.subscribe(params => {
        console.log(params); // Prints {id: "2"}
    });
}
Posted by: Guest on February-24-2021

Code answers related to "TypeScript"

Browse Popular Code Answers by Language