Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 2/4 Material, click on list item

My target is when clicking on any row of a list/table call a function. Couldn't make it work so now I just want to click on the 1st column of each row and call the function.

The component.html is like this, using @angular/material:

<ng-container *ngFor="let item of items">
    <md-grid-tile class="grid-box-row" ng-click="onRowClicked(item)"> {{item.id}} </md-grid-tile>
    ... ...

the compiled HTML is like this:

Screenshot of element in element hierarchy in Chrome DevTools

the function is in component.ts

private onRowClicked(item: Order) {
    this.loggerService.debug(item.id);
}

Everything seems good but the function is not hit when clicking.

like image 911
brewphone Avatar asked Dec 18 '25 21:12

brewphone


1 Answers

ng-click="onRowClicked(item)"

should be

(click)="onRowClicked(item)"

Check Template syntax on: https://angular.io/docs/ts/latest/guide/cheatsheet.html

like image 117
eko Avatar answered Dec 20 '25 15:12

eko