I need help in making the rows enable only when the checkbox is check. The default rows should be disabled but when the checkbox is only check, that row will be enabled. Her
Another aproach is create a directive
@Directive({
selector: '[enabledControl]'
})
export class EnabledControlDirective {
@Input() set enabledControl(condition: boolean) {
if (this.ngControl) {
if (this.ngControl.control) {
if (condition)
this.ngControl.control.enable();
else
this.ngControl.control.disable();
}
}
}
constructor(private ngControl : NgControl ) {
}
}
Then you can use like
<input class="col-md-6" formControlName="quantity"
[enabledControl]="row.get('checkbox_value').value" >
Have a look at the Demo & Src
Stack Blitz, Fork
Explanation:
[attr.disabled]="myForm.get('rows').value[i].checkbox_value ? null: ''"
attr.disabled
, here attr is for binding with properties which don't exist directly on an elementmyForm.get('rows').value[i].checkbox_value
, is fairly straight forward access to a form control's value.