1 year ago

#388170

test-img

hanushi

could not get query Selector inside <ng-template> in angular

I have table component.

I want to add a property to a element when [draggable]="true".

parent class

        <ngx-custom-table [value]="users" [draggable]="true">
         <ng-template #header let-columns>
          <tr> 
             // removed
          </tr>
          </ng-template>
         <ng-template #body let-data>
          <tr >
            <td>
            </td> 
          <td>{{ data.id }}</td>
         <tr>
        </ng-template>
      </ngx-custom-table>          

child class

 ngOnInit() {
       console.log( (<HTMLElement>document.querySelector('ngx-custom-table'))); // this is defined
    console.log( (<HTMLElement>document.querySelector('tr'))); // but this is null
    
  });

Why (<HTMLElement>document.querySelector('tr')); this is null??

How can I add a property to <tr> element?

html

angular

dom

queryselector

ng-template

0 Answers

Your Answer

Accepted video resources