I went through Mark's solution here : Angular2, disable button if no checkbox selected but I have more than 1 array, how do I modify the code in the link?
Or anyone with any other solution for doing this? I want to do this in angularJs 2.
I have a number of classes(arrays) & a number of subjects in those classes, & each subject corresponds to a checkbox, if one or more checkboxes are selected no matter they belong to same or different class, the button should be enabled. Here's the code, right now it considers only class1:
import {bootstrap} from 'angular2/platform/browser';
import {Component} from 'angular2/core'
@Component({
selector: 'my-app',
template: `
<label *ngFor="let cb of class1">
<input type="checkbox" [(ngModel)]="cb.state">{{cb.label}}<br/>
</label><br/>
<label *ngFor="let cb of class6">
<input type="checkbox" [(ngModel)]="cb.state">{{cb.label}}<br/>
</label>
<p><button [disabled]="buttonState()">button</button></p>
`
})
class App {
class1 = [{label: 'English(class1-5)'},{label: 'Maths(class1-5)'}];
class6 = [{label: 'English(class6-8)'},{label: 'Maths(class6-8)'}];
buttonState() {
console.log('buttonState() called');
return !this.class1.some(_ => _.state);
}
}