How can I add a click event to a particular header table pulled from an array using *ngFor in Angular?

Here is an array containing the headers for a table:

headers=['Ticket ID','Title','Date','Category','Read']

I am using this array to populate the headers in my table, like so:

<tr><th *ngFor="let header of headers" scope="col">{{ header }}</th></tr>

Currently, I am looking for a way to add a click event only to the Ticket ID and Date headers. Is there a way to do this?

Answer №1

One approach you can take is to filter events in the following manner:

<tr>
  <th *ngFor="let title of header" scope="col" (click)="handleHeaderClick(title)>
    {{ title }}
  </th>
</tr> 


public handleHeaderClick(title: string): void {
  if (title === 'Ticket ID' || title === 'Date') {
    // Include your code specific to these column types
  }
}

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

Utilize data binding in Typescript to easily link variables between a service and controller for seamless utilization

Is there a way to overcome the issue of value assignment not binding data in this scenario? For example, using this.arrayVal = someService.arrayVal does not work as intended. The objective is to simplify the assignment in both HTML and controller by using ...

Looking to include a badge within the nebular menu

Can someone assist me with adding a badge to the Nebular menu to display the inbox count dynamically? Any help would be greatly appreciated. Thanks! import { NbMenuItem } from '@nebular/theme'; export const MENU_ITEMS: NbMenuItem[] = [ { ti ...

What is the best way to retrieve child elements within bound innerHTML in Angular?

Upon examining the HTML structure, it appears as follows: <div [innerHtml]="someHtml"></div> The variable someHtml contains the following: public someHtml = '<code>test</code><code>another test</code>'; My ...

Utilizing the fscanf structure within a C file

When working with files, I have a specific set of inputs to read: Let's take a look at an example: 8 15 [1,1] v=5 s=4#o [4,2] v=1 s=9#x typedef struct{ int row; int column; int height; int width; char color[10]; }Tunnel; FILE* ...

Deleting a row from a table using TypeScript in Angular

I am currently working on a task management application and I am facing an issue with deleting a row when clicking the delete button. Below is the table structure in my HTML: <table *ngFor="let todo of todos; let i = index;" class="todo ...

How can you modify the height of the header field in Grid?

I have a single grid-tile: <md-grid-tile class="header"> <md-card class="content"> <md-card-header> <md-card-title>Monday</md-card-title> <md-card-subtitle>29.03.17</md-card-subtitle> ...

Is there possibly a problem with GridActionsCellItem and its props?

I'm encountering a problem with passing props into the GridActionsCellItem within the '@mui/x-data-grid'; columns; { field: 'actions', type: 'actions', width: 80, getActions: (params: any) =&g ...

Is it possible to execute TestCafe tests using TypeScript page objects that have not been utilized?

While working with TestCafe, I am implementing tests using the Page Objects pattern. I have already written some page objects in advance, even before their actual usage, as I am familiar with the page and know what to anticipate. However, when attempting ...

Having trouble accessing the boolean value of a webComponent Stenciljs input checkbox within an Angular Reactive form

When using my stenciljs input checkbox component in Angular inside a reactive form, I encounter an issue where the value received is inverted and stored as a string rather than a boolean. The console.log output seems correct, but the form group value is ...

Tips for modifying a nested reactive form while ensuring validation is maintained?

When retrieving data from a service in the form of an array, one might wonder how to bind this data in a nested form if there are potentially endless entries in the array. The form is expected to be pre-filled with this data, including validation for each ...

A guide on converting JSON strings into arrays using Javascript

In my JavaScript program, I have a Mocha test that checks if all available currencies are displayed in a drop-down list: it('displays all available currencies in drop down list', () => { return invoiceEditPage.details.currencyDropDown.dr ...

The Dynamic Duo: Typescript and Knex

I'm new to TypeScript and currently working on a node application using Express, Postgresql, and Knex. I'm a bit confused about when to apply type definitions in my code. Looking at other projects for guidance has left me even more puzzled as to ...

What is the most efficient way to perform an array join in Node.js, akin to the speed of MongoDB's $

Looking to implement a $lookup function in Node.js similar to the $lookup aggregation in MongoDB. I have a solution in mind, but I'm unsure about its performance when dealing with larger arrays or bigger objects. let users = [ {userId: 1, name: ...

In Angular, how do outputs impact parents when data consistently travels down from the root?

I have a question that may seem simple, but I am really trying to understand unidirectional data flow in Angular thoroughly. If change detection always happens from top to bottom, how does @Output impact a parent component? Could I be mistaken in my assu ...

Producer process writes a string into shared memory using varying sizes of character arrays, as long as the string length remains the same

I'm currently facing an issue with writing a string into shared memory using a producer process in the code snippet below. int main(){ char str[30]; scanf("%[^\n]", str); int shm_id = shmget((key_t)1234, sizeof(str), IPC_CREAT | 0666) ...

Updating displayed content based on orientation switch

Two components, A and B, are displayed simultaneously - A on the left and B on the right - when the device is in landscape mode. In portrait mode, either A or B will be displayed based on user selection. The components can transition from A to B and vice v ...

Arranging arrays within an array

I currently have an array of arrays that I need to sort based on the date value within one of the arrays. Here is the example: This is the initial array: arrayOfArray = [ ["Date", "01/02/2017", "02/02/2016"], ["Temperature", "19", "16"], ["Humidity ...

Is there a method to determine the string name value of the defining property in TypeScript?

Currently, I am working on developing a GraphQL application and facing a challenge with my GQL type definitions. organization: { type: OTCompany, astNode: fieldDefinitionAST(OTCompany.name, 'organization', [authDirective()]), description: ...

Utilizing jQuery to submit the form

After clicking the search icon, it displays an alert with the message ok, but not h. Based on the code snippet below, it is intended to display alerts for both ok and h. <?php if(isset($_POST['search'])){ echo "<script type='text/ ...

Unable to display JSON object in HTML in Angular due to a pipe error

Whenever I include the following code snippet: {{form}} The output is: [object Object] But when I modify it to: {{form | json}} An error occurs: TypeError: Converting circular structure to JSON --> starting at object with constructor 'TView&a ...