【发布时间】:2020-02-09 07:35:25
【问题描述】:
我有一个表,其数据来自角度 7 中的循环。这里一切正常,但根据我的 json,列中有 "enable":true 和 "enable":false。如果我的值是应选中 true 复选框,如果值为 false 则应在表中取消选中复选框。这是我的代码如下
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}];
}
【问题讨论】:
-
[checked]="user.enabled"
标签: javascript html angular