Ensure that the click event on the HTML element is only triggered one time

In my application, I have the following code snippet. The issue is that this code resides in each table column header. Therefore, whenever I click on a mat-select option, new values are generated and used in an *ngFor loop for mat-option.

The problem arises when clicking on one column header loads data into all mat-select options in the columns. This leads to difficulty in persisting user selections after clicking on another mat-select option.

Does anyone know how to limit ngFor to only once on mat-select or have any other suggestions on preserving user selection after clicking on another mat-select?

                                            <mat-form-field >
                                              <mat-select  placeholder="Banks" #{{headerName}} (click)=getColumnData(i) multiple>
                                                <!-- <mat-select-search [formControl]="bankMultiFilterCtrl"></mat-select-search> -->
                                               <mat-option #{{headerName}}. (onSelectionChange)="sorton(-1, -1)" id="clearopt">Clear filter</mat-option>
                                                <mat-option *ngFor="let record of currentddvalues " (onSelectionChange)="sorton(i, record)" id={{record}} >
                                                  {{record}}
                                                </mat-option>

                                              </mat-select>
                                            </mat-form-field>

Answer №1

To achieve the desired result, you can follow these steps:

Check out this Demo

.ts

isButtonClicked:boolean = false

fetchData(index){
    this.isButtonClicked = true
}

.html

<button (click)="!isButtonClicked ? fetchData(): false">Click me</button>

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 can I eliminate all duplicate entries from an array of objects in Angular?`

arr = new Array(); arr.push({place:"1",name:"true"}); arr.push({place:"1",name:"false"}); arr.push({place:"2",name:"false"}); arr.push({place:"2",name:"false"}); arr.push({place:"3",name:"false"}); arr.push({place:"3",name:"true"}); I'm curious about ...

Using AngularJS to retrieve a string array from data stored in Angular Firestore by invoking a function

As a newcomer to Angular, I am attempting to retrieve details from Firebase as a string array using the function below: Firestore : companies > details > app > name: "WM,TT,MP" getCompanies(): string [] { var appl: string [] = [] ; this.db.dat ...

Unable to reach the top while perfectly centered

I am currently struggling to create a perfectly centered popup menu that allows me to scroll all the way to the top. It seems like the transform property only affects visuals, so even though #content is set to top: 50%, I can't see everything at the t ...

Steps to reset an Angular material toggle button:1. Locate the

<div id="slider-group" *ngFor="let sliderToggle of sliderToggleGroup"> <div> <mat-slide-toggle (ngModelChange)="updateSlider($event,sliderToggle)" [(ngModel)]="sliderToggle.isChecked"> {{sliderToggle.na ...

Adjusting CSS to switch up the color scheme

Is there a way to allow users to change the background color of pull quotes by using the input type="color tag within a form element? Below is my current HTML structure: <form action="change.php" method="post"> name: <input type="text"> ...

Is it true that event.stopPropagation does not function for pseudoelements?

I am facing an issue with event handling in my ul element. The ul has three li children elements, and the ul itself has a useCapture event handler for click. In the click event handler, I successfully stop the event using event.stopPropagation(), and every ...

Creating a new formGroup and submitting it with model-driven form in Angular 2

Adding New Entries to FormArray Using input Field If I want to add values to an existing array through a form input, I can utilize the (click)="addAddress()" in the HTML file and define addAddress in the component.ts to update the values in an array withi ...

Retrieving the CSS property value from a website with Selenium

Hello there! For the purpose of verifying the font size of a CSS element on getbootstrap.com using Selenium in the Firefox browser, I rely on this particular script: #!/usr/bin/env perl use strict; use warnings; use Test::More; use Selenium::Firefox; my ...

Retrieve the highchart data from a PHP database table

Is there a way to display every row of data from my table in highcharts using PHP to JavaScript for each row? <script> series: [{ name: 'Instant Noodles', data: [<?php foreach ($query as $row){echo $row['noo ...

The MIME type 'text/html' is incompatible with stylesheet MIME type and is not supported

I have exhausted all possible solutions for the issue, from specifying the type for <link rel="stylesheet" href="./style.css" /> to using app.use(express.static('public')), but unfortunately, none of them seem to resolve the problem. index ...

Developing an Angular component using data retrieved from a JSON response

I want to design a model/class for my Angular App using the provided response template: { "id": {integer}, "name": {string}, "make": { "id": {integer}, "name": {string}, "niceName": {string} }, "model": { "id": {string}, "n ...

Achieving Consistent Aspect Ratios with Images in Flexbox Grid

I'm attempting to utilize flexbox for arranging elements in the layout shown below: -- ------ -- | | | | |--| |--| | | | | -- ------ -- Each corner 'box' contains an image with a square aspect ratio of 1:1. The center ...

atom-typescript - What could be causing the unrecognized Typescript configuration options?

I'm puzzled as to why I am encountering the errors depicted in the screenshot below. Atom is indicating that my tsconfig.json file has 'project file contains invalid options' for allowJs, buildOnSave, and compileOnSave. However, according ...

Error message: The Dockerfile unexpectedly cannot find the Json-server command during execution

I am attempting to create a Dockerized Angular + Json-Server application, but I am encountering difficulty setting up json-server. Even though I have installed it in the Dockerfile, when using docker logs, it tells me that it couldn't find the command ...

Applying left and right margins in Bootstrap container for better spacing

I am in search of a container that adjusts its width based on the page size like Bootstrap containers do, while also maintaining gaps between the container and the edges of the page when it becomes very small. Currently, the container occupies the entire ...

What is the best way to transfer a data string from my HTML document to my server (using either Node or Express) and trigger a specific function with that data?

Currently, my node.js server is operational and successfully creating an excel document by fetching data from an API using Axios. Now, I am looking to implement a feature where users can input a string on my HTML page, which will then be sent to the web se ...

Converting a string value into an object in Javascript using a command that functions similarly to eval in Python

When working with Python, the stringValue variable is often assigned as a string: stringValue = '{"DATA":{"VERSION":1.1, "STATE":True, "STATUS":"ONLINE"}}' To convert this string into a Python di ...

Incorporate a corner box feature to bring attention to the typed.js functionality

I have successfully integrated typed.js into my project and now I am looking to replicate the highlighted text with an excel-like box in one corner. I've managed to get the text typing out while also adding an SVG for the box in HTML, but I'm hav ...

Is there a way to send multiple actions to Node.js via a dropdown list using POST method?

I have encountered an issue where I am trying to include multiple actions in a single form within a dropdown list. However, I am only able to POST one action at a time. admin.html <form action="/start" method="post" id="tableForm"> <select id= ...

Using the Amazon Resource Name (ARN) of a Cloud Development Kit (CDK) resource in a different

Having trouble obtaining the ARN of my AWS CDK stack's Step Functions state machine for my lambda function. The ARN is constantly changing and I'm unsure how to access it. I attempted to create a .env file alongside the lambda function's in ...