Reputation: 39
I need to add an ID to the table
, I'm using PrimeNG so I don't have this table tag in my component, only the p-table
.
I tried [id]
and [attr.id]
but without success.
Any other suggestions please ?
Upvotes: 1
Views: 5690
Reputation: 696
You can do this way:
Mark p-table with an id for accessing his reference in ngAfterViewInit method:
<p-table #pTableId></p-table>
Then in Component.ts :
import {Table} from 'primeng/table';
export class MyComponent {
@ViewChild('pTableId') pTableRef: Table;
ngAfterViewInit() {
const table = this.pTableRef.el.nativeElement.querySelector('table');
table.setAttribute('id', 'myTableId');
}
}
Upvotes: 6
Reputation: 99
Why are you trying to add this id? You can do something like this
<p-table #some-id> </p-table>
and in your component
@ViewChild('some-id') myTable: any;
You can Refer to the table in your function (this.myTable) and look for children if that's what you are looking for. Let me know if that helped
Upvotes: 0