Obtaining the specified cell in a row when a button is clicked

I'm currently grappling with how to retrieve the value of the nth cell in the same row as the button that was clicked in angular2. I understand that I need to pass the $event value, but I'm unsure of how to extract the relevant data.

In app.component.html

<table>
      <thead>
        <tr>
          <th>Name</th>
          <th>Identifier</th>
          <th>Check Identifier</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td hidden>1</td>
          <td>Test</td>
          <td><button (click)="getData($event)">Display</button></td>
          <td>View</td>
        </tr>        
      </tbody>
    </table>

In app.component.ts, I have set up the following function:

getData(event: any) {
console.info(event);

// Unsure about this part
}

In the given scenario, how can I extract the value 1 from the first cell in the row after clicking the Display button?

Answer №1

  <tbody>
    <tr>
      <td hidden #nth>1</td>
      <td>Quiz</td>
      <td><button (click)="fetchData($event, nth)">Show</button></td>
      <td>Preview</td>
    </tr>        
  </tbody>
fetchData(event: any, el HTMLElement) {
  console.info(event);
  console.log(el.innerHTML);    
}

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 TS2339: Property does not exist on type 'object' - Typescript arrow function issue

In my experience with Angular, I have noticed that I encounter typescript compile errors quite often when using fat arrow functions within an rxjs stream. Despite being able to run the app and having it transpile successfully, I am curious about how to re ...

The most efficient method for receiving real-time updates from the server to the app is through Angular 7

Currently, I am in the process of developing an Angular 7 messages service (user to user) for my website. The approach I have taken involves receiving updates from the server (Yii2 REST API) every 3 minutes using an interval function (see code snippet belo ...

Tips for properly implementing an enum in TypeScript when using the React useState hook

What's the correct way to utilize my useState hook? I have this enum type: export enum Status { PENDING = 'pending', SUCCESS = 'success', ERROR = 'error', } And the useState hook: const [isValid, setIsValid] = use ...

What is the best way to restrict the key of an object type to only be within a specific union in TypeScript?

I need to create a set of server types in a union like this: type Union = 'A' | 'B' | 'C'; After that, I want to define an object type where the keys are limited to only certain options from this Union: // Use only 'A&ap ...

Angular Service encountered a NullInjectorError due to the absence of a provider for ViewContainerRef

After updating my Angular code from version 13 to 14.2.x, I discovered that the ComponentFactoryResolver has been deprecated. I decided to make changes to the instances of ComponentFactoryResolver in my library, but encountered the following error: ERROR E ...

Issues encountered when using PrimeNG tree select component with filter functionality

After successfully implementing the new primeng treeselect component with selection mode as "checkbox," I encountered an issue when trying to add a [filter]="true" as shown in the PrimeNG demo. <p-treeSelect [(ngModel)]="selectedNode1" [options]="nodes1 ...

Is there a way to specify patternProperties in a JSON schema and then map it to a TypeScript interface?

I'm in the process of developing a TypeScript interface that corresponds to a JSON schema. The specific field in my JSON schema is as follows: "styles": { "title": "Style Definitions", &qu ...

Exploring JSON data in Angular

I am currently working with a Json file that contains two different objects: readers and books. Here is an example of the structure: { "users": [{ "id": 1, "username": "peterB", }, { "id": 2, "username": "MaryC" ...

What is the process of converting a `typeorm` model into a GraphQL payload?

In my current project, I am developing a microservice application. One of the services is a Node.js service designed as the 'data service', utilizing nestjs, typeorm, and type-graphql models. The data service integrates the https://github.com/nes ...

After reinstallation, Angular CLI is still not functioning properly

I recently tried to upgrade my Angular CLI by uninstalling it and installing the new version. However, I encountered an issue where I am unable to run ng commands anymore due to an error message that keeps appearing: ng : File C:\Users\Sirius&bso ...

Generating custom error messages with specified format when utilizing routing-controllers

I'm currently working on a Node APP that utilizes the routing-controllers library. In the README file, there is a section titled Throw HTTP errors, which includes a self-explanatory example. However, I encountered an issue when attempting to replicat ...

Dynamic data manipulation with Angular ReactiveForms

One of the challenges I am facing involves using formArray for my list of products. Specifically, I am trying to access the value of product_code in my .ts file similar to [ngModel] so that I can manipulate the data accordingly. Can anyone provide guidance ...

The directive isn't responding to changes in the Angular scope.watch function

I am facing an issue with my Angular directive that monitors a list and generates a custom select when the list is modified. While it works perfectly on one page, it fails to work on another page. I am unable to determine why, but it seems like the watch f ...

Angular 2's Conditional Validation: A Comprehensive Guide

Angular 2 offers straightforward validation, which is a great feature. However, the challenge lies in making a required field optional based on another field's selection. Below are the validation rules: this.contractsFilter = this.fb.group({ selec ...

What could be causing the "undefined object" warning within this optional chain?

I encountered this issue: buyTicketData?.pricingOptions resulting in this error message: [tsl] ERROR in /Applications/MAMP/htdocs/wp-content/plugins/tikex/tikexModule/components/BuyTicket/PricingOptionInvoiceItemsFormFieldsCheckboxes.tsx(280,25) TS2 ...

Typescript's default string types offer a versatile approach to defining string values

Here is an example code snippet to consider: type PredefinedStrings = 'test' | 'otherTest'; interface MyObject { type: string | PredefinedStrings; } The interface MyObject has a single property called type, which can be one of the ...

Error: Unable to locate the type definition file for the '@babel' package

I am currently working on a new project and here is the content of my package.json file. { "name": "dapp-boilerplate", "version": "1.0.0", "main": "index.js", "license": "MI ...

What could be causing the "buffer is not a function" error to occur?

As a beginner with observables, I'm currently working on creating an observable clickstream to avoid capturing the 2 click events that happen during a double-click. However, I keep encountering this error message:- Error: Unhandled Promise rejection ...

Error: Model function not defined as a constructor in TypeScript, mongoose, and express

Can anyone help me with this error message "TypeError: PartyModel is not a constructor"? I've tried some solutions, but now I'm getting another error as well. After using const { ... } = require("./model/..."), I'm seeing "TypeError: C ...

DiscordJS is throwing a TS2339 error stating that the property 'forEach' is not found on the type 'Collection<string, GuildMember>'

Upon attempting to utilize the code provided, I encountered the error messages Property 'forEach' does not exist on type 'Collection<string, GuildMember> and Property 'size' does not exist on type 'Collection<string, ...