Skip to content

Commit

Permalink
fix: formControl Input for select
Browse files Browse the repository at this point in the history
  • Loading branch information
felixroos committed Mar 29, 2019
1 parent c0c7f17 commit bcbbc51
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/ui/src/lib/select/select.component.ts
Expand Up @@ -2,7 +2,7 @@ import {
Component, EventEmitter, forwardRef, Input, OnChanges, OnInit, Output,
ViewChild, ViewEncapsulation, ElementRef, ChangeDetectionStrategy, ChangeDetectorRef
} from '@angular/core';
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
import { ControlValueAccessor, NG_VALUE_ACCESSOR, FormControl } from '@angular/forms';
import { List, ListConfig, Selection } from '@ec.components/core';
import { Item } from '@ec.components/core';
import { PopComponent } from '../pop/pop.component';
Expand Down Expand Up @@ -70,6 +70,8 @@ export class SelectComponent<T> implements ControlValueAccessor, OnInit, OnChang
@ViewChild(SearchbarComponent) searchbar: SearchbarComponent;
/** Subject that is nexted when an item is being selected (clicked or entered on) */
toggleItem: Subject<Item<T>> = new Subject();
/** The formControl that is used. */
@Input() formControl: FormControl;

constructor(
public elementRef: ElementRef,
Expand Down Expand Up @@ -119,6 +121,10 @@ export class SelectComponent<T> implements ControlValueAccessor, OnInit, OnChang
}
this.config = Object.assign({ solo: this.solo }, this.config);
const value: Array<T> = Array.isArray(this.value) ? this.value : this.value ? [this.value] : [];

if (!this.formControl) {
this.formControl = new FormControl(value || []);
}
this.selection = new Selection(value, this.config);
this.cdr.markForCheck();
this.selection.update$.subscribe(() => {
Expand Down

0 comments on commit bcbbc51

Please sign in to comment.