“Typscript -URL -Parameter” Code-Antworten

Typscript -URL -Parameter

// get all search params (including ?)
const queryString = window.location.search;
// it will look like this: ?product=shirt&color=blue&newuser&size=m

// parse the query string's paramters
const urlParams = new URLSearchParams(queryString);

// To get a parameter simply write something like the follwing
const paramValue = urlParams.get('yourParam');
Zwazel

Holen Sie sich URL -Params in TypeScript

import {Router, ActivatedRoute, Params} from '@angular/router';
import {OnInit, Component} from '@angular/core';

@Component({...})
export class MyComponent implements OnInit {

  constructor(private activatedRoute: ActivatedRoute) {}

  ngOnInit() {
    // Note: Below 'queryParams' can be replaced with 'params' depending on your requirements
    this.activatedRoute.queryParams.subscribe(params => {
        const userId = params['userId'];
        console.log(userId);
      });
  }

}
Repulsive Raven

Ähnliche Antworten wie “Typscript -URL -Parameter”

Fragen ähnlich wie “Typscript -URL -Parameter”

Weitere verwandte Antworten zu “Typscript -URL -Parameter” auf JavaScript

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen