Pārlūkot izejas kodu

Revising stnafield directive to accept multiple CSS classes as array or string with spaces

Richard Knight 6 gadi atpakaļ
vecāks
revīzija
bcd1d104ac
1 mainītis faili ar 4 papildinājumiem un 4 dzēšanām
  1. 4 4
      src/app/dynaform/directives/dynafield.directive.ts

+ 4 - 4
src/app/dynaform/directives/dynafield.directive.ts

@@ -56,7 +56,7 @@ export class DynafieldDirective extends NgControl implements OnInit, OnDestroy {
 		private container: ViewContainerRef,
 		@SkipSelf() private cc: ControlContainer,
 		@Optional() @Self() @Inject(NG_VALIDATORS) private validators: Array<Validator | ValidatorFn>,
-		@Optional() @Self() @Inject(NG_ASYNC_VALIDATORS) private asyncValidators: Array<AsyncValidatorFn>
+		@Optional() @Self() @Inject(NG_ASYNC_VALIDATORS) private asyncValidators: AsyncValidatorFn[]
 	) {
 		super();
 	}
@@ -84,7 +84,7 @@ export class DynafieldDirective extends NgControl implements OnInit, OnDestroy {
 			// Support the recursive insertion of Dynaform components
 			if (type === 'DynaformComponent') {
 				if (meta.template) {
-					(<any>instance).template = meta.template;
+					(instance as any).template = meta.template;
 				}
 				meta = meta.meta;
 			}
@@ -106,7 +106,7 @@ export class DynafieldDirective extends NgControl implements OnInit, OnDestroy {
 				el.id = cssId;
 			}
 			if (cssClass) {
-				const classesToAdd = Array.isArray(cssClass) ? cssClass : [cssClass];
+				const classesToAdd = Array.isArray(cssClass) ? cssClass : [...cssClass.split(/\s+/)];
 				el.classList.add(...classesToAdd);
 			}
 
@@ -115,7 +115,7 @@ export class DynafieldDirective extends NgControl implements OnInit, OnDestroy {
 				// We're dealing with a custom form control which implements the ControlValueAccessor interface,
 				// so we need to wire it up!
 				this.name = name;
-				this.valueAccessor = <FFCCustom>this.component.instance;
+				this.valueAccessor = this.component.instance as FFCCustom;
 				// Attach sync validators
 				/*
 				const ngValidators = this.component.injector.get(NG_VALIDATORS, null);