title: how to select all checkboxes in angular 6?
body: <p>how to select all checkboxes in angular 6?</p>
  
  <p>I'm trying to make a table with checkboxes but I cant set a checkbox that check true all checboxes in per page.
  I want to check all checkboxes but it isn't working correctly.</p>
  
  <p><strong>html</strong></p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>    &lt;table id="myTable"&gt;
        &lt;tbody &gt;
              &lt;/tbody&gt;
              &lt;tbody &gt;
                &lt;tr &gt;
                  &lt;th&gt;
                    &lt;input type=" checkbox" (change)="checkAll(this)"&gt;
          &lt;/th&gt;
          &lt;th&gt;
            id
          &lt;/th&gt;
          &lt;th&gt;
            fname
          &lt;/th&gt;
         
          &lt;/tr&gt;
        &lt;/tbody&gt;
        &lt;tbody *ngFor="let item of result" style="border:1px solid #D3D3D3"&gt;
          &lt;td&gt;
            &lt;input type="checkbox" (change)="getCheckboxValues($event,item)" [checked]="check_true"&gt;
          &lt;/td&gt;
          &lt;td&gt;
            {{ item.id }}
          &lt;/td&gt;
          &lt;td&gt;
            {{ item.fname }}
          &lt;/td&gt;
        &lt;/tbody&gt;
      &lt;/table&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p><strong>component.ts</strong></p>
  
  <pre><code>       getCheckboxValues(ev, data) {
      let obj = {
        "order": data
      }
      let selected_rows = [];
  
      if (ev.target.checked) {
        // Pushing the object into array
        this.newArray.push(obj);
      } else {
        let el = this.newArray.find(itm =&gt; itm.order === data);
  
        if (el)
          this.newArray.splice(this.newArray.indexOf(el), 1);
        if (this.newArray.length == 0) {
          this.newArray = [];
        }
      }
  
      if (this.newArray.lenght &gt; 0) {
        for (let i in this.newArray) {
          selected_rows.push(this.newArray[i].order.bulkid);
  
          this.selected_rows = selected_rows;
        }
      }
    }
  
    checkAll(ele) {
  
      var checkboxes = document.getElementsByTagName('input');
      if (ele.checked) {
          for (var i = 0; i &lt; checkboxes.length; i++) {
              if (checkboxes[i].type == 'checkbox') {
                  checkboxes[i].checked = true;
              }
          }
      } else {
          for (var i = 0; i &lt; checkboxes.length; i++) {
              if (checkboxes[i].type == 'checkbox') {
                  checkboxes[i].checked = false;
              }
          }
      }
      console.log(ele)
  }
  </code></pre>
  
  <p>I'm trying to make a table with checkboxes but I cant set a checkbox that check true all checboxes in per page.
  I want to check all checkboxes but it isn't working correctly.</p>