Skip to content

Commit 7a27629

Browse files
Reduce for property complexity
1 parent 8243df2 commit 7a27629

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

angular-reactive-validation/src/validation-messages/validation-messages.component.ts

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -47,24 +47,17 @@ export class ValidationMessagesComponent implements AfterContentInit, OnDestroy
4747

4848
@Input()
4949
set for(controls: FormControl | (FormControl|string)[] | string) {
50-
if (Array.isArray(controls)) {
51-
if (controls.length === 0) {
52-
throw new Error(`arv-validation-messages doesn't allow declaring an empty array as input to the 'for' attribute.`);
53-
}
50+
if (!Array.isArray(controls)) {
51+
controls = controls !== undefined ? [controls] : [];
52+
}
5453

55-
this._for = controls.map(control => {
56-
if (typeof control === 'string') {
57-
return getFormControlFromContainer(control, this.controlContainer);
58-
} else {
59-
return control;
60-
}
61-
});
62-
} else if (typeof controls === 'string') {
63-
this._for = [getFormControlFromContainer(controls, this.controlContainer)];
64-
} else {
65-
this._for = [controls];
54+
if (controls.length === 0) {
55+
throw new Error(`arv-validation-messages doesn't allow declaring an empty array as input to the 'for' attribute.`);
6656
}
6757

58+
this._for = controls.map(control => typeof control === 'string' ?
59+
getFormControlFromContainer(control, this.controlContainer) : control);
60+
6861
this.validateChildren();
6962
this.controlStatusChangesContainer.unsubscribeAll();
7063
this.controlStatusChangesContainer.subscribe(this._for, control => control.statusChanges, true);

0 commit comments

Comments
 (0)