0

I need to hide a particular column in the HTML table when the page loads. I used ngOnInit() to hide the column. But it works only for the <th> and not for <td>.

But, when I used in click function it works for both <th> and <td>. How can I achieve this?

this is my code used in ngOnInit

ngOnInit() {
$('td:nth-child(19),#tr1 th:nth-child(8)').hide();
}
OM PRAKASH
  • 393
  • 1
  • 5
  • 20
suganya
  • 21
  • 4

1 Answers1

0

You have to make the particular column depend on a boolean element using ngIf. For example:

// ----- component.html -----
<table style="width:100%">
  <tr>
    <th>column1</th>
    <th>column2</th> 
    <th *ngIf="!eliminar">columnInvisible</th>
  </tr>
  <tr>
    <td>1</td>
    <td>2</td> 
  </tr>
  <tr>
    <td>3</td>
    <td>4</td> 
  </tr>
</table>

// ------ component.ts ------
export class LoginViewComponent implements OnInit {

  eliminar: boolean;

  ngOnInit() {
    this.eliminar = true;
  }

}