3

I have angular4 with materialize table Api so I am trying to get row data when user click on the row but its not passing data, How can i pass data to component from view any help will be appreciated ?

app.component.html

<div class="table-container">
<mat-table>
       <ng-container matColumnDef="eventType">
            <mat-header-cell *matHeaderCellDef> Event Type </mat-header-cell>
            <mat-cell *matCellDef="let element"> {{element.eventType}} </mat-cell>
          </ng-container>
          <!--<button (click)="newMessage()" class="button">New Message</button>-->
          <mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
          <mat-row *matRowDef="let row; columns: displayedColumns;" (click)="highlight(row._id,$event)"></mat-row>
        </mat-table>
      </div>

app.component.ts

highlight(id,event){
        console.log('Event',event);
    }
1
  • It clearly seems to be working for me, please check stackbiltz here Commented Dec 5, 2017 at 19:28

1 Answer 1

2

Change to following in your template app.component.html

<mat-row *matRowDef="let row; columns: displayedColumns;" (click)="highlight(row,$event)"></mat-row>

and you should write your click handler in your component app.component.ts

highlight(row,evt) :void{
   //console.log(row,evt);
}

Remove ._id from (click)="highlight(row._id,$event)" from your code.refer this

Sign up to request clarification or add additional context in comments.

1 Comment

error __zone_symbol__error: Error: Template parse errors: Can't bind to 'row-id' since it isn't a known property of 'mat-row'. 1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.