no0x9d / ngx-strongly-typed-forms

Strongly typed definitions for Anglulars `@angular/forms`
MIT License
59 stars 11 forks source link

How to use?

npm install ngx-strongly-typed-forms

Attention: Since version 7.2 this project does no longer follow semver version numbers. The major and minor version represents the compatible Angular version and patch versions are bugfixes in this library.

Now you can import generic FormControl, FormGroup and FormArray and use them instead of the classes from @angular/forms

import {FormArray, FormControl, FormGroup} from 'ngx-strongly-typed-forms';

If you want to use the FormBuilder you have to provide it from your app module

import { ReactiveFormsModule } from '@angular/forms';
import { NgxStronglyTypedFormsModule } from 'ngx-strongly-typed-forms';

@NgModule({
  imports: [ ReactiveFormsModule, NgxStronglyTypedFormsModule ]
})
export class AppModule {
}

All usages of AbstractControl and its subclasses now supports generic types.

This change is not backwards compatible with Angulars AbstractControl. All occurrence at minimum must be typed with AbstractControl<any>, or at best with an interface which describes all form fields.

How does it work

This project does not modify any angular classes but provides new strongly typed definitions for Angulars own forms. For convenience it re-exports these classes directly from Angular.

Hints

Alternatives

Something does not work as expected

Beside the known limitations, everything that is possible with the native Angular Forms should be possible too. If you find something not working as expected then there might be a problem in my type definitions. Please open an issue with an minimal example to reproduce the problem and I will try to fix it asap.

Limitations