“Angular Get URL Params” Kode Jawaban

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. 
    });
}
GutoTrosla

Angular Get Parameter URL

Routes

export const MyRoutes: Routes = [
    { path: '/items/:id', component: MyComponent }
]


Component

import { ActivatedRoute } from '@angular/router';
public id: string;

constructor(private route: ActivatedRoute) {}

ngOnInit() {
   this.id = this.route.snapshot.paramMap.get('id');
}
Obnoxious Osprey

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']
);
Victor Grk

Parameter URL Angular

// example url: details?id=2

constructor(private activatedRoute: ActivatedRoute) {
  this.activatedRoute.queryParams.subscribe(params => {
        console.log(params); // Prints {id: "2"}
    });
}
Ham-Solo

Dalam Angular Cara Mendapatkan URL Router Tanpa Param Param

this.router.url.split('?')[0] 
Defeated Dotterel

Jawaban yang mirip dengan “Angular Get URL Params”

Pertanyaan yang mirip dengan “Angular Get URL Params”

Lebih banyak jawaban terkait untuk “Angular Get URL Params” di TypeScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya