Is there a way to retrieve data from Angular RC4 routing?

Within the app routes:

{ path: 'calculator', component: CalculatorComponent, data: {physical: Physical}},

In the settings component:

if(this.selectedPhysical) {
   this.router.navigate(['/calculator', this.selectedPhysical ]);
}

The result of the navigation attempt is incorrect:

http://localhost:3000/calculator;pK_Physical=4;fK_Measurement=2;dateString=5/22/2016;weight=270;height=70;hips=27;waist=51;neck=18.5

How can I properly pass the data to the route?

In the calculator component, I have the following code. How can I access the data passed in through the route?

ngOnInit() {
    this.route
       .data
       .subscribe(v => this.selectedPhysical = <Physical>v);
            
   console.log("phys = " + this.selectedPhysical);
}

If anyone knows how to achieve this, please share your knowledge.

Answer №1

In order to ensure your code is working with the most updated data, it's important to place the code that relies on this data inside the subscribe(...) callback.

ngOnInit() {

   ** The issue lies here **, despite my attempts to solve it in various ways, nothing seems to work. It always ends up being undefined.

   this.route
       .data
       .subscribe(v => {
            this.selectedPhysical = <Physical>v;
            console.log("phys = " + this.selectedPhysical);
       });

   // unsure about these          
   this.selectedSex = this.userSettings.sex;

   //console.log('route id =' + 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

Checking the token's validity using the API within the AuthGuard canActivate method in Angular8

As I navigate through certain routes, I need to validate each refresh request. To achieve this, I am utilizing Angular's AuthGuard. The challenge lies in the canActivate method where I aim to perform validation using an online API. The API endpoint i ...

The package.json entry for "abc-domains" is not functioning correctly even though it is set to "latest" version

Unique Scenario Imagine there's a package called xyz-modules that I've developed. The package.json file in my project looks like this: ... "devDependencies": { "@company/xyz-modules": "latest", ... } ... After ...

Error429 was received from a GET request made to the Imgur API

Encountering a Request failed with status code 429 error from the Imgur API despite using a new Client_ID that hasn't been used before, Here is my Api.ts: const imgurClientId = process.env.NEXT_PUBLIC_Client_ID const BASE = "https://api.imgur. ...

Tips for integrating TypeScript with Vue.js and Single File Components

After extensive searching online, I have struggled to find a straightforward and up-to-date example of setting up Vue.js with TypeScript. The typical tutorials out there either are outdated or rely on specific configurations that don't apply universal ...

Issue with the close button on ngb-alert not functioning properly

As I develop my website, I have incorporated an ngb-alert component to display an alert message to users upon login. While the alert itself is functioning properly, I have encountered an issue with the close button being misaligned, and I am struggling to ...

Angular 2: Embracing the Power of Hierarchical Selection

My goal is to create cascading selects where each option in a dropdown menu can lead to its own set of unique child options. This will result in a hierarchical structure of selectable items. To accomplish this, I have defined a class named fieldSelect tha ...

What is the best way to dynamically add or utilize a pipe in Angular 8?

I have a special pipe in my Angular 8 application that I created: import { Pipe, PipeTransform } from '@angular/core'; import { MyService} from '../_services/my.service'; @Pipe({ name: 'myPipe' }) export class MyPipe imp ...

Refreshing the chosen input field within an Angular context

One of the components I have allows users to dynamically edit and add multiple addresses. Here's how the UI appears: https://i.sstatic.net/3v3ND.png Whenever I add or edit an address, the entire form field values get reset. This results in a new add ...

Encountering a memory issue while trying to read and display Excel data in an Angular 2 application

Currently, I am working on an asp.net web API that utilizes OpenXML SDK for Excel to read data from an Excel file and display it in an Angular2 application. The dataset consists of approximately 70,000 rows that need to be displayed all at once without any ...

The type 'Observable<void>' cannot be assigned to the type 'Observable<JSON>'

fetchStepData(): Observable<JSON> { this.headers = new Headers(); this.headers.append('Content-Type', 'application/json; charset=utf-8'); let options = new Req ...

What is the best way to declare multiple types that require specific props?

Trying to implement the following type: type DataTypes = | Link | Event | People | Article | Department | PageSearch | OfficeSearch | CatalogSearch | DocumentSearch | KnowledgeSearch; When implemented this way, it functions correctly: ...

Why am I encountering numerous errors while attempting to install Juice Shop?

My attempt to install the juice shop app from GitHub resulted in 63 errors showing up after running the command npm install. [riki@anarchy]: ~/juiceShop/juice-shop>$ npm install (Various warnings and engine compatibility issues) Multiple vulnerabilit ...

Issue with debugging Azure Functions TypeScript using f5 functionality is unresolved

I am encountering issues running my Azure TypeScript function locally in VS code. I am receiving the errors shown in the following image. Can someone please assist me with this? https://i.stack.imgur.com/s3xxG.png ...

Declaring a custom Angular Pipe

I've created a custom Pipe to filter a list of items and integrate it into my Angular/Ionic application. // pipes/my-custom-filter/my-custom-filter.ts import { Pipe, PipeTransform } from '@angular/core'; @Pipe({ name: 'myCustomFilt ...

Leverage the compiler API to perform type inference

Exploring TypeScript's compiler API for basic type inference has proven to be a challenge with limited helpful information found in documentation or online searches. My goal is to create a function inferType that can determine and return the inferred ...

Utilizing Next.js and React to interact with Open AI through API requests

I'm currently experimenting with the OpenAI API to develop a chatbot using React, TypeScript, and Next.js. I am facing an issue where clicking the send button in the UI does not trigger any action. Even after adding console.log statements, nothing sho ...

Issue with Typescript and react-create-app integration using Express

I'm relatively new to Typescript and I decided to kickstart a project using create-react-app. However, I encountered an issue while trying to connect my project to a server using express. After creating a folder named src/server/server.ts, React auto ...

Issue with hardhat failing to detect balance transfer from smart contract

I am currently in the process of creating tests for a smart contract that I have developed. Below is a simplified version of the smart contract: Please Note: I have hard-coded the value to ensure accuracy regarding the amount leaving the contract. functio ...

In order of service - avoid repeating the initial service upon the next user click if the second service was unsuccessful

Seeking assistance. I am new to Angular + RxJS, so please bear with me if this task seems easy. The concept is to submit a form that includes multiple input fields, one of which is for uploading an image. When the user clicks the submit button, the first ...

Tips for triggering an event from a function instead of the window

Everything is functioning as expected, with the event listener successfully capturing the custom event when it is dispatched from the window and listened for as loading, all seems to be working well. const MyLib = mylib(); function mylib() { const re ...