Skip to content

Feature: expose the ngDefaultControl #1372

Open
@gogoout

Description

@gogoout

Currently all the form controls have implemented the ControlValueAccessor. While if the users wants to wrap the form controls themselves, it will be quite redundant. They have to implement the ControlValueAccessor all over again.

In here, the way is much more easier thanks to the ngDefaultControl which Angular exposed.

@Component({
  selector: 'my-wrapper',
  template: '<input ngDefaultControl>',
  providers: [
    {
      provide: NG_VALUE_ACCESSOR,
      useExisting: forwardRef(() => NumberInputComponent),
      multi: true,
    },
  ],
})
export class MyWrapper implements ControlValueAccessor {
  @ViewChild(DefaultValueAccessor) private valueAccessor: DefaultValueAccessor;

  writeValue(obj: any) {
    this.valueAccessor.writeValue(obj);
  }

  registerOnChange(fn: any) {
    this.valueAccessor.registerOnChange(fn);
  }

  registerOnTouched(fn: any) {
    this.valueAccessor.registerOnTouched(fn);
  }

  setDisabledState(isDisabled: boolean) {
    this.valueAccessor.setDisabledState(isDisabled);
  }
}

The way doesn't work in the nativescript-angular because the ngDefaultControl is not exposed in here.
By simply put the ngDefaultControl selector in all the value-accessor. We can implement the same feature.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions