Angular 2 and .NET Core 2.0 triggering an endless loop upon page refresh detection

My application, built with dotnet core 2.0 and angular 2, allows me to view member details. The process begins with a list page displaying all the members from a SQL Server database. Each member on the list has a link that leads to an individual details page. A member.service.ts manages this service. However, when I refresh the details-member.component.html page, the server spins endlessly without returning any data. The only error message I encounter is "firstName" is not defined. Strangely, everything works perfectly fine without the need for refreshing.

member.service.ts

import { Http } from '@angular/http';
import { Injectable } from '@angular/core';
import 'rxjs/add/operator/map';

@Injectable()
export class MemberService {

constructor(private http: Http) { }

getAllMembers(){
    return this.http.get('/api/members').map(res => res.json());
}

getMember(id:any){
    return this.http.get("/api/members/" + id).map(res => res.json());
}
}

details-member.component.ts

import { Component, OnInit } from '@angular/core';
import { MemberService } from '../../../services/member.service';
import { ActivatedRoute, Router } from '@angular/router';

@Component({
   selector: 'app-details-member',
   templateUrl: 'details-member.component.html'
})

export class DetailsMemberComponent implements OnInit {
   member: any;
   memberId:number;

constructor(
    private route: ActivatedRoute,
    private router: Router,
    private memberService: MemberService,
) { 
    route.params.subscribe(p => {
        this.memberId = +p['id'];
        if (isNaN(this.memberId) || this.memberId <= 0) {
          router.navigate(['/member/list-members']);
          return; 
        }
      });
}

ngOnInit() { 
    this.memberService.getMember(this.memberId)
    .subscribe(
      v => this.member = v,
      err => {
        if (err.status == 404) {
          this.router.navigate(['/members/list-members']);
          return; 
        }
      });
    }
}

details-member.component.html

<div class="page-header clearfix detailHeading">
    <h1 class="text-muted">Demographic Details</h1>
</div>

<div class="jumbotron">
    <div class="row">
        <div class="col-md-6">
            <p>Full Name : <b>{{ member.firstName }} {{ member.middleName }} 
{{ member.lastName }}</b></p>
        <p>Gender : <b>{{ member.gender }}</b></p>
        <p>Date of Brith : <b>{{ member.dateOfBirth | date }}</b></p>
        <p>Age : <b>{{ member.dateOfBirth | age }}</b></p>
        <p>Race : <b>{{ member.race }}</b></p>
        <p>Education : <b>{{ member.education }}</b></p>
        <p>Address : <b>{{ member.address }}</b></p>
        <p>Emergency Contact Name : <b></b></p>
        <p>Emergency Contact Address : <b></b></p>
        <p>Emergency Contact Phone : <b></b></p>
    </div>
        <div class="col-md-6">
            <hr>
            <div class="alert alert-warning" role="alert">
                Created : <b>{{ member.createdDate | date:'medium' }} by {{ member.createdBy }}</b>
            </div>
            <div class="alert alert-warning" role="alert">
                Last Update : <b>{{ member.updatedDate | date:'medium' }} by {{ member.updatedBy }}</b>
            </div>
        </div>

</div>

The error message says:

fail: Microsoft.AspNetCore,NodeServices[0] ERROR TypeError: Cannot read propery 'firstName' of undefined
. This issue occurs solely upon refreshing the details page.

Answer №1

The issue's root cause remains a mystery to me, but I successfully resolved it by modifying the asp-prerender-module tag within the index.cshtml file. Specifically, I added an x in front of the tag, as shown below.

<app xasp-prerender-module="ClientApp/dist/main-server">Application is Loading...</app>

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

Sort by the recent messages of another observable

I'm attempting to sort through messages in one observable based on the messages from another observable. navCmds --A----B---C--A------D-----------------C-----D----E---> navNotifications ----A----X---B-C-A---D------------------------DCA-- ...

Expanding unfamiliar categories

Currently, I am working with Gutenberg blocks in a headless manner. Each Gutenberg block is defined by the following structure: type Block = { name: string; className?: string; key?: string | number; clientId: string; innerBlocks: Block ...

There is no index signature that includes a parameter of type 'string' in the specified type

I have a background in mobile app development and am looking to learn more about TypeScript. How can I declare a map object with the form [string:any]? The error is occurring at line: map[key] = value; Element implicitly has an 'any' type becaus ...

Begin the Angular 4 project by loading it with RequireJS

I am currently in the process of constructing an Angular4 application using the ng command. Successfully, I can build and execute it with ng serve. Now, my aim is to incorporate RequireJS so that the Angular4 application can load and run smoothly. Despit ...

What could be causing the first() rxjs operator to repeatedly return an array?

I'm currently facing an issue with a service that has the following function signature: getSummary(id: string, universe: string): Observable<INTsummary[]> My requirement is to retrieve only the first item in the INTsummary[] array when calling ...

Unable to access or modify properties within a function passed as an argument

deleteDialog(item, func: Function) { this.dialogService .open(ConfirmDialogComponent, { context: { title:"Are you sure?", cancelClss: "info", confirmClss: "danger", }, ...

Encountering a discord bot malfunction while on my Ubuntu server

My discord bot runs smoothly on my Windows 10 setup, but when deployed to the server running Ubuntu Server 20, it encounters a specific error. The issue arises when trying to handle incoming chat messages from the server. While I can read and respond to m ...

Fetching DataItem from a Kendo Grid using a custom button in an Angular application

I have been working on transferring the dataItem from a Kendo grid to an Angular 6 component. Here is my setup: <kendo-grid [data]="view | async" [height]="533" (dataStateChange)="onStateChange($event)" (edit)="editHandler($even ...

What is the best way to generate a dynamically interpolated string in JavaScript?

I'm currently developing a reusable UI component and am exploring options to allow the user of this component to provide their own template for a specific section within it. Utilizing TypeScript, I have been experimenting with string interpolation as ...

Event-Propagation in Angular 5 with mat-expansion-panel within another component

In my project, I am facing a challenge where I need to create multiple mat-expansion-panels within one mat-expansion-panel. Everything works fine except for the issue that when I try to open a child-panel, it triggers the close-event of the parent-panel. ...

Mastering the use of Action.Submit in adaptive cards to simulate user input

I am trying to implement MessageFactory.SuggestedActions within my "welcomeCard" adaptive card. Essentially, in my adaptive card (welcome card), I have several buttons for the user to click on, each with an Action.Submit type. { "type" ...

What is the best way to update queryParams without activating subscribe functions?

Hello, I am currently in the process of developing an angular app with multiple routes. When navigating to a specific page, the queryParams trigger the subscribe function. While on the page, I need to be able to change the queryParams without triggering ...

Show the Search Results from Angular 2 in a Separate Component

When I search, the names are displayed on a suggestion list without any issues because they are not in a separate component. Search HTML <input type="text" placeholder="Search" (keyup)="getSuggestion($event.target.value)"> <div class="suggest ...

Can ES6 class getters, setters, and private properties be utilized in TypeScript with an interface?

I'm currently using TypeScript and trying to figure out how to implement an interface in a class that utilizes ES6 getters and setters. Is it even possible? When I use the code below, errors are highlighted in the class. For instance: (property) S ...

Issue with Lazy Loading in Angular 4 Universal

I recently created a new Angular CLI project to delve into server-side rendering with Angular Universal. Everything was set up and running smoothly, until I decided to implement lazy-loading for a module named 'lazy'. After implementing lazy-lo ...

The defaultValue of the Observable TextArea is blank space following the transmission of a sendMessage using SignalR in a Typescript

i am currently in the process of modifying a basic SignalR Chat feature. Here is the situation: when a user sends a message, the message gets sent successfully. However, the textarea from which it was sent remains filled with empty space (aside from the p ...

Creating a generic class for third-party API requests in NestJS

I'm working on a NestJS application that involves making third-party API requests. Every function requires the same code to retrieve data, causing repetition. How can I streamline this process by creating a common class for handling GET or POST reque ...

What is the best way to eliminate the content of an element using javascript/typescript?

The progress bar I'm working with looks like this: <progress class="progress is-small" value="20" max="100">20%</progress> My goal is to use javascript to remove value="20", resulting in: <progre ...

Verifying the Loading of a Module in Angular 5

I am working on Angular 5 and I am trying to figure out how to determine if a module has been loaded already so that I can avoid displaying the spinner unnecessarily. Currently, this is my code: constructor(private loaderService: LoaderService, private ro ...

Can components be SSGed individually rather than entire pages?

I am currently working with Next.js and I am wondering if there is a way to statically generate and display the database values in the header and footer components used across all pages. While getStaticProps can generate pages statically, it doesn't ...