Get data from an Angular 12 hyperlink

Here is the link to my questionnaire: http://localhost:4200/EditQuestionnaire;id=1;name=Random%20Questionnaire

I have included this code in the ngOnInit() function, however, I am having trouble retrieving the values:

ngOnInit(): void {
        this.route.params.subscribe(params => {
            this.questionnaireName = params['name'];
            this.questionnaireID = params['id'];
        });
    }
    

Answer №1

To utilize ActivatedRoute, you can implement the following code snippet:

constructor(private route: ActivatedRoute){
    this.route.queryParams.subscribe(params => {
      this.questionnaireName = params['name'];
      this.questionnaireID = params['id'];
    });
}

Ensure that your URL is formatted correctly like so:

http://localhost:4200/EditQuestionnaire?id=1&name=Random%20Questionnaire

Answer №2

let userID:string;

class User {
    constructor(private route: ActivatedRoute){
        this.userID = this.route.snapshot.params.id;
    }
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How do I display a single record from an array object in Angular?

Encountering a dilemma when attempting to retrieve a single record from an array like this data.service.ts getOneBookDetail(isbn:any) { const headers = new HttpHeaders().set("Content-Type", "application/json"); ...

Angular is throwing an error stating that the argument type 'typeof MsalService' cannot be assigned to the parameter type 'MsalService'

I'm currently facing a challenge in creating an instance of a class in TypeScript/Angular. Within my project, there is a specific scenario where I need to call a method from an exported function that is located within another class in TypeScript. co ...

One-time export feature similar to Typescript's export_once functionality

When I have the following code structure: File1.ts function someFunction(){...} export default someFunction(); and then File2.ts import File1 from "./File1"; File3.ts import File1 from "./File1"; My question is, will the export de ...

Learning to implement the latest language features in JavaScript on older runtimes using TypeScript

Currently, I am faced with a dilemma in my TypeScript project involving the use of flatMap. The issue arises from the fact that this project needs to be compatible with Node.js versions as old as v10, which do not support flatMap. I had assumed that TypeS ...

Handling generic errors in Angular 2's Http responses

I'm currently developing an Angular 2 application that involves API requests. I was curious if there is a way to create a universal error handling mechanism. For example, I'd like to automatically redirect users to the login page if the API retur ...

Transitioning Angular from TSLint to ESLint: Addressing the Banana-In-Box Issue

Encountering major hurdles during the transition from TSLint to ESLint for my Angular project. I've set up a new project (currently in Angular 9) and then proceeded to upgrade to Angular 10.2. Following the instructions outlined in the @angular-eslint ...

An error persists in PhpStorm inspection regarding the absence of AppComponent declaration in an Angular module

After creating a new Angular application, I am encountering the issue of getting the error message "X is not declared in any Angular module" on every component, including the automatically generated AppComponent. Despite having the latest version of the An ...

What is the best way to transform this Ajax query into an HTTP client request in Angular 8?

I have an ajax request that looks like this: var data = { REQUEST: 'GetFeatureInfo', SERVICE: 'WMS', VERSION: '1.1.1', LAYERS: layerName, STYLES: '', FORMAT: 'image/png', INFO ...

Scrolling content with the mdldialogservice in Angular2

I am utilizing the MdlDialogService to trigger a help dialog from my home component: launchHelpDialog(){ this.dialogService.showCustomDialog({ component: HelpComponent, animate: true, isModal: true, styles: {'widt ...

Encountering an Issue while Attempting to Deploy Angular 6 on Her

I recently pushed my Angular 6 application to Heroku. Although the deployment was successful, the page is not loading properly. An error message on the page reads: An error occurred in the application and your page could not be served. If you are the ap ...

Modifying the response header in a node.js middleware: A step-by-step guide

I've been researching this question extensively on Google, but unfortunately, none of the solutions seem to work for me. The issue I'm facing is related to adding a specific property to the response header called "isAuth," which needs to be set ...

Angular Components unexpectedly lose background transparency when using Transparent-Background-PNG in the foreground

Hey there! I'm currently working on a landing page and I have this amazing idea to use a stunning picture of clouds with a transparent background layered over a beautiful landscape. The only problem is that when I try to implement it, the transparency ...

Create a dynamic Prisma data call by using the syntax: this.prisma['dataType'].count()

I'm currently working on implementing a counting function that can be utilized in all of my objects. In my 'core' file, Prisma is involved in this process. This allows me to execute commands like this.user.count() or this.company.count() I ...

Issue with MUI Select custom MenuItem functionality not functioning as expected

Having an issue with MUI's MenuItem in conjunction with Select and rendering it within a separate component. Check out the codesandbox for reference. The setup is as follows: import { Select } from "@material-ui/core"; import CustomMenuIte ...

Installation of Angular-cli is successful but system still shows error of Angular-cli not being installed

https://i.sstatic.net/dINO9.png These are the packages included in my project: "license": "MIT", "dependencies": { "@angular/animations": "^4.0.3", "@angular/common": "^4.0.3", "@angular/compiler": "~4.0.0", "@angular/core": "~4.0.0", ...

What is a more efficient method for incorporating optional values into an object?

Currently, I am utilizing the optional addition feature in this way: ...(!!providerId && { providerId }), ...(!!practiceId && { practiceId }), Is there a more elegant shorthand method to replace this logic, such as: yield createRemark ...

Struggling with slow TypeScript compilation?

My current setup involves TypeScript 2.2.1, but I've been facing prolonged compilation times when running tsc. In an attempt to gather more information, I decided to utilize the --diagnostics option. However, I soon discovered that the "Total time" di ...

Error Encountered When Trying to Import BrowserAnimationsModule in Angular 5: Unexpected Token "<"

As I try to integrate the BrowserAnimationModule into my Angular 5 project, a rather foolish error keeps popping up. Error: (SystemJS) Unexpected token < SyntaxError: Unexpected token < at eval (<anonymous>) at Object.eval ...

Creating an HTTP method handler function in Next.js API routes with an unspecified number of generic parameters

Looking to create a wrapper function in NextJS for API routes that can handle multiple HTTP methods with different handlers. For example, check out the TS playground interface GetResponse { hello: string, } // empty object type PostResponse = Record&l ...

Access your Angular 5 application as a static webpage directly in your browser, no server required!

I need to run an Angular 5 application in a browser by manually opening the index.html file without the use of a server. My client does not have access to any servers and simply wants me to provide a package (dist folder) for them to double-click on the in ...