diff --git a/components/select/select.ts b/components/select/select.ts old mode 100644 new mode 100755 index c409f03c..44c742f9 --- a/components/select/select.ts +++ b/components/select/select.ts @@ -192,7 +192,6 @@ export class SelectComponent implements OnInit { @Input() public placeholder:string = ''; @Input() public idField:string = 'id'; @Input() public textField:string = 'text'; - @Input() public initData:Array = []; @Input() public multiple:boolean = false; @Input() @@ -209,6 +208,27 @@ export class SelectComponent implements OnInit { } } + @Input() + public set active(selectedItems:Array) { + if (!selectedItems || selectedItems.length === 0) { + this._active = []; + } + else { + let areItemsStrings = typeof selectedItems[0] === 'string'; + + this._active = selectedItems.map((item:any) => { + let data = areItemsStrings + ? item + : { id: item[this.idField], text: item[this.textField] }; + + return new SelectItem(data); + }); + } + + this.data.emit(this._active); + } + + @Output() public data:EventEmitter = new EventEmitter(); @Output() public selected:EventEmitter = new EventEmitter(); @Output() public removed:EventEmitter = new EventEmitter(); @@ -216,16 +236,20 @@ export class SelectComponent implements OnInit { public options:Array = []; public itemObjects:Array = []; - public active:Array = []; public activeOption:SelectItem; public element:ElementRef; + public get active():Array { + return this._active; + } + private inputMode:boolean = false; private optionsOpened:boolean = false; private behavior:OptionsBehavior; private inputValue:string = ''; private _items:Array = []; private _disabled:boolean = false; + private _active:Array = []; public constructor(element:ElementRef) { this.element = element; @@ -310,10 +334,6 @@ export class SelectComponent implements OnInit { public ngOnInit():any { this.behavior = (this.firstItemHasChildren) ? new ChildrenBehavior(this) : new GenericBehavior(this); - if (this.initData) { - this.active = this.initData.map((data:any) => (typeof data === 'string' ? new SelectItem(data) : new SelectItem({id: data[this.idField], text: data[this.textField]}))); - this.data.emit(this.active); - } } public remove(item:SelectItem):void {