0

I have a table whose data comes from loop in angular 7.Here every thing is working fine but as per my json, there is "enable":true and "enable":false in a column.Here if my value is true checkbox should be checked and if value is false checkbox should be unchecked in table.Here is my code below

app.component.html

<table>
<tr *ngFor="let user of users">
<td>{{user.id}}</td>
<td>{{user.name}}</td>
<td><input type="checkbox" checked></td>
</tr>
</table>

app.component.ts

import { Component, OnInit } from '@angular/core';
import { CommonserviceService } from './../utilities/services/commonservice.service';
@Component({
  selector: 'app-home',
  templateUrl: './home.component.html',
  styleUrls: ['./home.component.css']
})
export class HomeComponent implements OnInit {
  getListData: any;

  constructor(private commonserviceService: CommonserviceService) { }

  ngOnInit() {


  }

  users = [{"id":1,"name":"test","enable":true},{"id":2,"name":"test","enable":false}];


}
UIAPPDEVELOPER
  • 583
  • 5
  • 18
  • 37

1 Answers1

1

Try this:

<table>
    <tr *ngFor="let user of users">
        <td>{{user.id}}</td>
        <td>{{user.name}}</td>
        <td><input type="checkbox" [checked]="user.enable"/></td>
    </tr>
</table>
Daniel.V
  • 2,322
  • 7
  • 28
  • 58