实际上,我正在尝试使用 Angular 4 cli 和 JSON 数组来创建自定义数据表。我已经成功创建了带有动态列和动态行的表。所以,我想通过使用下拉复选框样式来修复表格的过滤列。这是我的代码:
<div class="col-md-12">
<div class="input-group">
<div class="input-group-btn" dropdown>
<button type="button" class="btn btn-primary dropdown-toggle" dropdownToggle>Filter
<span class="caret"></span>
</button>
<div class="dropdown-menu" *dropdownMenu>
<div class="checkbox" *ngFor="let column of columns, let i = index" >
<label for="column">
<input [(ngModel)]="column" type="checkbox" id="column" name="column" value="column" checked="true"> {{column}}
</label>
</div>
</div>
</div>
</div>
而我的 component.ts 文件代码是:
StudentsDetails = [];
columns: string[] = [];
constructor(private newService: StudentsService) { }
ngOnInit() {
this.newService.fetchData()
.subscribe(responseStudentsDetails => {
this.StudentsDetails = responseStudentsDetails;
this.columns = Object.keys(this.StudentsDetails[0]);
})
};
因此,当我尝试调用 [(ngModel)]="column" 时。它向我显示错误,例如:未捕获(承诺):错误:无法分配给引用或变量!