我有一个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。
我想不出一个好方法来做到这一点,而且我一直在寻找某种可以使用的初始化事件,但是没有运气。(与正在发生的(更改)事件无关)
希望您能提供帮助,并在此先感谢
您可以绑定checked
喜欢
<input type="checkbox" class="form-control" (change)="ServiceAddOrRemove($event, option.id)" name="choose"
[checked]="ids.indexOf(option.id) != -1">
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句