Lets say, I want to add method to NgForm (class)
NgForm.prototype.markAsDirty = function (): void {
    let f: NgForm = this;
    Util.forEach(f.form.controls, (k, v: AbstractControl) => {
        v.markAsDirty(false);
    });
};
Is this somehow possible in typescript?
I am aware of:
but it works only for interfaces, not classes.
In Angular and TypeScript you usually use inheritance like
export class MyForm extends NgForm {
  ...
}
and register your custom class to be used throughout your application instead of the original class.
bootstrap(AppComponent, [FORM_PROVIDERS, FORM_DIRECTIVES, provide(NgForm, { useClass: MyForm})]);
I haven't investigated if there any additional things to consider that are special to the NgForm, FORM_PROVIDERS or FORM_DIRECTIVES to make this work properly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With