• Skip to main content
  • Skip to primary sidebar

Web Development Archive

  • Archive
You are here: Home / Angular / Console only the clicked item

Console only the clicked item

import { Component, EventEmitter, inject, Output } from '@angular/core';
import { ResultsService } from '../../helpers/results.service';
import { Results } from '../../helpers/results.model';
import { TableModule } from 'primeng/table';
import { CommonModule } from '@angular/common';

@Component({
selector: 'app-results-table',
standalone: true,
imports: [TableModule, CommonModule],
templateUrl: './results-table.component.html',
styleUrl: './results-table.component.scss'
})
export class ResultsTableComponent {
data: Results[] = [];
@Output() click = new EventEmitter<string>();

private readonly _resultsService = inject(ResultsService);

ngOnInit(): void {
this.data = this._resultsService.getResultsData() as Results[];
}

onClick(item: Results): void {
console.log('Clicked: ', item.grandPrix);
this.click.emit(item.grandPrix);
}
}
<p-table *ngIf="data" [value]="data" [tableStyle]="{ 'min-width': '50rem' }" stripedRows>
<ng-template pTemplate="header">
<tr>
<th>Futam</th>
<th>Dátum</th>
<th>Győztes</th>
<th>Csapat</th>
<th>Körök száma</th>
</tr>
</ng-template>
<ng-template pTemplate="body" let-item>
<tr class="result-row" (click)="onClick(item)">
<td>{{ item.grandPrix }}</td>
<td>{{ item.date | date: 'yyyy-MM-dd' }}</td>
<td>{{ item.winner }}</td>
<td>{{ item.team }}</td>
<td>{{ item.laps }}</td>
</tr>
</ng-template>
</p-table>

Filed Under: Angular

About Gabor Flamich

I'm a web developer and designer based in Budapest, Hungary. In recent years, I've documented hundreds of solutions I came across during development. This site is an archive for useful code snippets on WordPress, Genesis Framework and WooCommerce. If You have any questions related to WordPress development, get in touch!

Primary Sidebar

  • angular.io
© 2026 WP Flames - All Right Reserved