【发布时间】:2016-11-25 01:24:58
【问题描述】:
我有一个 Angular 2 应用程序,我使用 ngFor 来处理一堆复选框。当我初始化这个组件时,我需要根据天气设置复选框的状态,一个 id 存在于一个数组中
<div *ngFor="let option of listOptionResponse.options" class="col-md-12">
<div class="col-lg-12">
{{option.headline}}
</div>
<div class="col-lg-2 col-md-2 ">
<input type="checkbox" class="form-control" (change)="ServiceAddOrRemove($event, option.id)" name="choose">
</div>
</div>
在组件中我有一个数组,如果 options.id 存在于这个数组中,我想将其设置为 true。
我想不出一个好的方法来做到这一点,我一直在寻找某种初始化事件来使用,但没有运气。 (这与现有(更改)事件无关)
希望能帮到你,在此先感谢
【问题讨论】: