I would like to "check" a checkbox based on it's id.
template HTML:
div class="panel panel-default" *ngFor="let optionsList of option.options">
<div class="panel-heading panel-heading-divider"><input type="checkbox" id="" value=""></div>
<div class="panel-body"></div>
</div>
controller component:
foo(selected: number): void {
this._service.foo(bar, options, selected).subscribe(
res => {
this.validation = res;
if(this.validation.furtherAdditions.length > 0) {
this.validation.furtherAdditions.forEach(
option =>
//'checked' checkbox by id from validation
);
}
},
error => this.errorMessage = <any>error
);
In other words, I have a bunch of checkbox inputs created dynaamically using ngFor. The data is variable, as it is populated from an API. I have recorded the validation ids (what needs to be 'checked') from the API response, and for each ID, I would like to select it. How would I go about this using angular2?
Aucun commentaire:
Enregistrer un commentaire