我有要显示的对象列表
public weeks = [
{ value: 'All', display: 'All',isChecked: false },
{ value: 'Mon', display: 'Mon',isChecked: false },
{ value: 'Tue', display: 'Tue',isChecked: false },
{ value: 'Wed', display: 'Wed',isChecked: false },
{ value: 'Thu', display: 'Thu',isChecked: false },
{ value: 'Fri', display: 'Fri',isChecked: false }
];
app.component.html
<span *ngFor="let week of weeks">
<label>
<input type="checkbox" name="weeks" [(ngModel)]="week.isChecked" class="week" >
{{week.display}}
</label>
</span>
问题是它现在绑定选中的复选框。
app.component.ts
this.weeks.forEach((month) => {
var i = this.selected_weeks.indexOf(month.week);
if(i != -1) {
week.isChecked = true;
console.log(week.isChecked);
}
});
在组件中,它标记该对象为true但在视图中未选中