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

Validating a single field name with various DTO types based on conditions in a NestJS application

There is a field named postData in EmailTypeDto, but it has different types based on conditions. It may be confusing to explain in words, but the code makes it clear. export class EmailTypeDto { @IsEnum(EmailType) public type: EmailType; @ValidateIf ...

What is the best way to assign a value to an ngrx reducer/action in order to update the state?

As a newcomer to Angular ngrx, I am in the process of integrating it into my 'standard beginner-project' by replacing all @Input()s and @Output()s. While incrementing and decrementing the state is straightforward, I am faced with the challenge of ...

Create a simulated class to serve as a property within a service

Currently, I'm working on an Ionic application and have created an AlertService class with two properties: messageAlert: Alert; errorAlert: Alert; The Alert class belongs to the Ionic framework, so I cannot modify it. To mock the Alert class, I came ...

Display JSON Array information in a template using a component

I have made an API call and received the response in this.order.info this.http.get(this.order_info_url+'/'+this.order_id) .subscribe( response => { this.order_info = response.json(); console.log(this.order_info[0]); }, ...

Incorporate a new element into a dynamic, responsive form using Angular

I’m struggling to create a nested reactive form in Angular 5. I can add items at one level successfully, but I’m having trouble adding items at the second level. ngOnInit() { this.orderForm = this.formBuilder.group({ customerName: '', e ...

How can we eliminate the modal-open class in Angular when transitioning to a different URL?

Currently, I am facing an issue with a bootstrap modal. There is a button inside the modal which upon clicking should navigate the current component to another component named 'questions'. The problem arises when the new component is loaded, as t ...

Toggle the visibility of certain side menu items based on user authentication status

Using Angular 2, I created a website where I need to enable or disable certain sidebar components based on user login data. The user's login data is stored in JSON and a token is passed via Qwebchannel for authentication on localhost. My goal is to dy ...

Exploring TypeScript Object Properties in Angular 2

How can I extract and display the ID and title of the Hero object below? The structure of the Hero interface is based on a Firebase JSON response. hero.component.ts import {Component, Input} from 'angular2/core'; import {Hero} from '../mod ...

Using Angular 10 to make an HTTP POST request, with the goal of appending a string

Whenever I try to send a post request to an api endpoint, I keep encountering an error with status code 500. name: "HttpErrorResponse" ok: false status: 500 statusText: "Internal Server Error" Below is the code I am using: var selected ...

Expanding a class in Typescript by adding a function with the same name but varying properties and types

class A { play(a: string): string{ return a; } } class B extends A { play(c: string, b: number): string{ return c + ' ' + b.toString(); } } let x = new A(); console.log(x.play('John')); let y = new B(); console.lo ...

Clicking on a href link inside a scrollable div-container causes it to malfunction, causing the page to jump

I have a draggable div container that contains dynamically generated content. In order to display this container, I use the following code: $( function() { $( "#dialog-message" ).dialog({ modal: true, height: 400, buttons: { Fertig: functi ...

Transforming the window property in distinct entry points for TypeScript

During the initial page load, I am looking to transfer data from a template to a TypeScript file by attaching it to the window object. I want each page to utilize the same variable name for its specific data (window.data). An example of this can be seen in ...

Believed I had a clear understanding of the situation

Within the following code snippet, I am utilizing a service (Angular) to extract text using a fileReader and implementing a promise for the asynchronous part. However, I am encountering an issue that appears to be related to scope, which is causing confusi ...

Utilizing Components for Efficient Development in Angular

I have three different types of objects: A - FirstName - LastName B - FirstName - LastName - MiddleName C - FirstName My goal is to create a component that can be used to easily create these objects using a simple form where I can input the necessa ...

Angular 2: Accessing the parent component from the output

I am a beginner in Angular 2 and I've been exploring ways to access the value of an attribute from a parent component using the @Output feature. Below is the code snippet: ParentPage.ts export class ParentPage { name: string; constructor(){ ...

Cached images do not trigger the OnLoad event

Is there a way to monitor the load event of my images? Here's my current approach. export const Picture: FC<PictureProps> = ({ src, imgCls, picCls, lazy, alt: initialAlt, onLoad, onClick, style }) => { const alt = useMemo(() => initial ...

The double curly brackets in Angular for text interpolation are failing to work, causing the variable values to not be shown on display

I'm having trouble getting the details of a student to display on my app. Here's the code: import { Component, OnInit } from '@angular/core'; import { Student } from '../student'; import { ActivatedRoute } from '@angular/ ...

Having trouble with accessing properties like `d3.svg()`, `d3.scale()` and other features of d3js within an Angular 2 environment

Struggling to incorporate d3.js into angular2. Below is the command I used to install d3 in Angular2: npm install --save d3 install --save-dev @types/d3 This is how my package.json appears: { "name": "my-app", "version": "0.0.0", "license": "M ...

Constructing a Primeng MessageService causes a blank webpage to appear

After downloading the QuickStart CLI of PrimeNG for Angular, I added a second component for a chart that was already included in the UI components. Everything seemed to be set up correctly, but when I saved, I ended up with a completely blank page for the ...

Different ways to reference a variable in Typescript without relying on the keyword "this" throughout the codebase

Can we eliminate the need to write "this" repeatedly, and find a way to write heroes, myHero, lastone without using "this"? Similar to how it is done in common JavaScript. https://i.stack.imgur.com/TZ4sM.png ...