0

I try to make a directive to enable/disable a form. I found a solution for control by doing this code:

export class DisableControlDirective {

  @Input() set appDisableControl(condition) {
    const action = condition ? 'disable' : 'enable';
    this.ngControl.control[action]();
  }

  constructor(private ngControl: NgControl) { }
}

Is there an equivalent to NgControl injection to access to FormGroup ?

<form 
  [formGroup]="group"             <!-- Access to this -->
  [appDisableGroup]="!isEditable" <!-- From this -->
></form>
Leix
  • 125
  • 12
  • Seems you're looking for `ControlContainer` or `FormGroupDirective` – yurzui Aug 28 '18 at 09:35
  • Yes but it does not let me enable or disable the group. I can only access to getters – Leix Aug 28 '18 at 09:44
  • https://stackoverflow.com/questions/47937639/how-to-make-a-disabled-reactive-form-editable-in-angular2 – Eliseo Aug 28 '18 at 09:44
  • `FormGroupDirective` has a getter `control` that returns `FormGroup`. https://github.com/angular/angular/blob/master/packages/forms/src/directives/reactive_directives/form_group_directive.ts#L95 – yurzui Aug 28 '18 at 09:46
  • this.group.form.disable() and this.group.form.enable() after constructor(private group: FormGroupDirective) {} was the solution, thanks ! – Leix Aug 28 '18 at 09:48

0 Answers0