1

I m trying to access to some information in a table by HTML and it is working, but I would like to do it after clicking a button and not onInit, so I guess that I need to do it by Javascriptor Typescript

It would be perfect to create the table by HTML but filling it by Javascript or Typescript after clicking the button.

The table is the following: HTML

<table id="myTableSystems" class="table table-bordred table-striped">
    <thead>
      <th>{{ 'Checkbox' | translate }}</th>
      <th>{{ 'MappingMult' | translate }}</th>
    </thead>
    <tbody>
      <tr *ngFor="let receiver of testCase.receivers;" class="pointer">
        <td>
          <input type="checkbox">
        </td>
        <td>{{receiver.mappingMult}}</td>
      </tr>
    </tbody>
</table>
4
  • what info do u need to access after click Commented Jan 3, 2018 at 14:45
  • where is the code for button Commented Jan 3, 2018 at 14:45
  • your code is commented - uncomment it Commented Jan 3, 2018 at 14:45
  • 1
    Are you trying to say that you want to render the table on user action instead of rendering it through component life-cycle? Commented Jan 3, 2018 at 15:00

1 Answer 1

2

In your component.ts file you will need to create a function to fill the object "testCase".

I'm not sure how the component is getting/receiving the data for "testCase". You will need to refactor the logic so that you get the data for "testCase" in the fillData function.

component.ts

  public fillData(): void {
    this.testCase.receivers = [{mappingMult: 'data'}];
  }

component.html

<button type="button" (click)="fillData()" class="">Click To Fill Data</button>

<table *ngIf="testCase" id="myTableSystems" class="table table-bordred table-striped">
  <thead>
    <th>{{ 'Checkbox' | translate }}</th>
    <th>{{ 'MappingMult' | translate }}</th>
  </thead>
  <tbody>
    <tr *ngFor="let receiver of testCase.receivers;" class="pointer">
      <td>
        <input type="checkbox">
      </td>
      <td>{{receiver.mappingMult}}</td>
    </tr>
  </tbody>
Sign up to request clarification or add additional context in comments.

1 Comment

This is exactly what I was looking for. I totally forgot the *ngIf for the table. Thanks

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.