Issue with Angular 6 and Chrome: Event listener ($event) occasionally throws the error "unable to access property 'value' of null"

It appears that the buttons are being iterated correctly using ngFor, and upon inspection they have the correct attributes. However, when clicked, the function in the controller sometimes claims the parameter is 'undefined', happening randomly about half the time.

Here's the error message I'm encountering: ERROR TypeError: Cannot read property 'value' of undefined at (the line where the attribute is passed as a parameter in the controller)

Previously, everything worked fine when all the logic was contained within its controller. Recently, I refactored it to utilize a service + interceptors. So far, I've incorporated the headers and params in the service.

The strange thing is that everything functions properly in Firefox without any errors, but Chrome seems to be the only browser experiencing this bug. If I continue clicking on it, errors persist until suddenly it starts working again. You can view a screen recording here:

Note: If I refrain from repeatedly clicking -- nothing occurs. Checking the network tab reveals that the http call isn't triggering at all.

Code snippet below:

Front end:

<div *ngFor="let button of lvl0 | errorfix">
  <!-- Buttons reiterated with ngIF -->
  <button mat-raised-button color="accent" [attr.data-param1]=" button['md:0/413349530_Level 0 – Section'] | lvl0clean "
    class="lvl0button" (click)="reveallvl1($event)" (click)="stepper.reset()" (click)="resetAllSteps()">
    {{ button['md:0/413349530_Level 0 – Section'] | lvl0clean }}
  </button>
</div>

Service:

initialisingDocs() {
  let headers = new HttpHeaders();

  headers = headers.append(
    "Authorization",
    "Basic " + btoa("SOMETHINGSOMETHING")
  );
  headers = headers.append(
    "Content-Type",
    "application/x-www-form-urlencoded"
  );
  return this.http.get(this.ROOT_URL + "initialising", { headers });
}

Controller:

constructor(private service: DocsService) {
  // Initializing the first set of buttons

  this.lvl0 = this.service.initialisingDocs().subscribe(data => {
    this.lvl0 = data;
    console.log(this.lvl0);
  });
}

For the next level of buttons:

reveallvl1($event) {
  this.service
    .lvl1Docs($event.target.attributes["data-param1"].value) **// <<ERROR LINE>>**
    .subscribe(data => {
      this.lvl1 = data;
      console.log(data);

      this.step1Folder($event.target.attributes["data-param1"].value);
    });
}

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

Error in TypeScript: The object may be null when using the window.open method

Is there a way to implement this code in Typescript? window.open(externalUrl, '_blank').focus(); Encountering the following TypeScript error: Object is possibly 'null'.ts(2531) I attempted the following solution without success: ...

How can models be aggregated in SQL by connecting them through other models?

I am working with a backend express API that utilizes sequelize. In my sequelize models, a Citizen is linked to a Street, which in turn is associated with a Town, and the Town is connected to a State. I can easily count the citizens on a specific Street by ...

Strategies for efficiently managing multiple subscriptions in an Angular form using minimal code and best practices

I am currently working on an Angular form that includes multiple select options managed by Subscriptions. However, I find myself writing a lot of code for each Subscription and would like to improve this process. Could someone provide some best practices ...

Implementing Typescript with React: Assigning event.target.name to state

I am facing an issue with a React state that has specific named keys defined in an interface... Despite trying a potential solution based on the state keys, I am still encountering an error... { [x: string]: string; }' provides no match for the sign ...

Transforming a mongodb operation into an asynchronous function using await and async syntax

After calling the function to retrieve data from MongoDB, an undefined error occurs. It is suspected that converting the function to an async/await function may resolve this issue. However, there is uncertainty on how to make this conversion without disrup ...

Transforming Javascript into Typescript with node modules in Visual Studio 2015

After developing a JavaScript web app using npm and webpack, I successfully converted all the .js files to .ts using the PowerShell command found here. Now, I am looking to transition to a VS2015 TypeScript project but struggling to find guidance on how ...

The type 'Observable' does not contain the properties found in type 'User'

I am trying to retrieve user data from Firestore, but encountering an error The type 'Observable' is missing the following properties from type 'User': email, emailVerified, uidts(2739) user.service.ts import { Injectable } from &apo ...

Creating a new Angular library with SASS using Angular CLI

I'm currently working on an Angular6 app where I need to create a library. However, after generating the library project, I noticed that Angular CLI is automatically creating components with .css files instead of .scss files. Is there any way I can f ...

Can TypeScript provide a way to declare that a file adheres to a particular type or interface?

Experimenting with different TypeScript styles has been quite enjoyable, especially the import * as User from './user' syntax inspired by node. I've been wondering if there is a way to specify a default type as well. Suppose I have an interf ...

Steer clear of utilizing the "any" type in your Express.js application built with

I have a node/express/typescript method that looks like this: // eslint-disable-next-line export const errorConverter = (err: any, req: any, res: any, next: any) => { let error = err if (!(error instanceof ApiError)) { const statusCode = e ...

There is no assigned value in scope for the shorthand property. You must either declare one or provide an initializer

I'm just starting out with TypeScript. Encountering the error 'No value exists in scope for the shorthand property 'firstName'. Either declare one or provide an initializer.' while using Prisma with Next.js to create a new user in ...

How can I retrieve header values in the canActivate function in Angular?

Depending on the value of userRole received from the header, I need to redirect to different user pages. angular.routing.ts { path: '', pathMatch: 'full', redirectTo: '/login' }, { path: 'user', loadChildren: &apo ...

`How to prevent Query parameters from being lost upon reloading in Nextjs Router while maintaining a clean URL structure?`

My challenge lies in sending data via router.push to a page with dynamic room id (src/pages/editor/[roomid].tsx) in Next.js. I want the URL to stay clean so users can easily edit their username in the URL if needed. When initially loaded, router.query suc ...

Having trouble directing my attention towards a Mat card when using viewchildren in Angular

My current challenge is trying to focus on a specific card from a list of mat cards Despite my efforts, I keep encountering an error that reads: Cannot read property 'focus' of undefined Access the code on StackBlitz The desired functionali ...

NextAuth is failing to create a session token for the Credential provider

Currently, I am in the process of developing an application using the t3 stack and am facing a challenge with implementing the credential provider from nextauth. Whenever I attempt to log a user in, I encounter an error in the console displaying the messag ...

The Angular HTTP request is coming back with a status of 0, even though I was anticipating

I need to access a server with various routes. The routes are as follows: app.use('/401', (req, res) => res.status(401).end()); app.use('/403', (req, res) => res.status(403).end()); app.use('/404', (req, res) => res. ...

What is the best way to pass a state within a route component in react-router?

... import { useNavigate, NavigateFunction } from "react-router"; ... function Form(): JSX.Element { const navigateToCountry = (country: string) => { // Code to navigate to country page with the given country } const [selectedCount ...

Can the PrimeNG p-fileUpload component be configured to launch from a specific directory?

Utilizing the PrimeNG p-fileUpload component for file uploads. Looking to customize the default folder that opens when the select file button is clicked. Would like it to open in a specific location such as Desktop or Videos. Is there a method to achieve ...

Having trouble displaying child nodes in MatTreeView with Angular 14?

In an Angular project, I am attempting to display a private group's data from GitLab (utilizing a public one for testing purposes). To achieve this, I have implemented the NestedTreeView component. While the parent nodes are displaying correctly, I am ...

The npm installation process has come to a sudden halt

Starting a web application in Angular 17 has been my goal. I typically run npm install followed by ng serve. However, this process suddenly stopped working. To troubleshoot, here are the steps I've taken: Updated npm to the latest version (10.2. ...