Skip to content
This repository was archived by the owner on Jan 5, 2022. It is now read-only.
This repository was archived by the owner on Jan 5, 2022. It is now read-only.

Error when using inputs styled as form-control outside of forms #46

@dmeenhuis

Description

@dmeenhuis

Hi,

I'm using this library and overall it seems to work just fine. However, I have some cases where I have inputs styled as form-control, without actually using them within a <form> tag.

When I combine that with these directives, the application breaks with the following error:

ERROR TypeError: Cannot read property 'getControl' of null
    at FormControlDirective.get [as control] (ng-bootstrap-form-validation.js:413)
    at FormControlDirective.get [as validClass] (ng-bootstrap-form-validation.js:372)

I suspect the culprit is the following line of code:

https://github.com/third774/ng-bootstrap-form-validation/blob/master/projects/ng-bootstrap-form-validation/src/lib/Directives/form-control.directive.ts#L60

The assumption made here is that formDirective must be defined, however when looking at the getter for formDirective, it says:

get formDirective(): any {
  return this.parent ? this.parent.formDirective : null;
}

Which means a null value could be returned, which in turn results in the error I've described above.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions