Commit af7de04d authored by Merzough Münker's avatar Merzough Münker
Browse files

fix(RxapFormBuild): throw if form definition can not be injected.

parent 4290cdab
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
# Changelog

## [0.2.1]
### Fixed
- (RxapFormBuild): throw if form definition can not be injected.

## [0.2.0]
### Added
- (RxapFormBuild): add support for injectable validators
+1 −1
Original line number Diff line number Diff line
{
  "name": "@rxap/forms",
  "version": "0.2.0",
  "version": "0.2.1",
  "private": false,
  "author": "Merzough Münker",
  "homepage": "https://gitlab.com/rxap/packages",
+17 −2
Original line number Diff line number Diff line
import {
  Injector,
  StaticProvider
  StaticProvider,
  isDevMode
} from '@angular/core';
import {
  Constructor,
@@ -108,7 +109,21 @@ export class RxapFormBuilder<Form extends FormDefinition = FormDefinition> {
      providers: this.providers
    });

    const form = injector.get(this.definition, new this.definition());
    let form: Form & Record<string, Function>;


    // don't use the notFoundValue feature of the injector.
    // if used for each call of the get method an "empty" or "fallback"
    // instance is created

    try {
      form = injector.get(this.definition);
    } catch (e) {
      if (isDevMode()) {
        console.warn('Could not inject the definition instance. Fallback and call the constructor of the definition class.');
      }
      form = (new this.definition()) as Form & Record<string, Function>;
    }

    const controls: Record<string, AbstractControl> = {};