ng2-encrm-components
Version:
59 lines (46 loc) • 1.37 kB
text/typescript
import { Component, OnInit, EventEmitter, ElementRef, Input, Output } from '@angular/core';
import { NG_VALUE_ACCESSOR, ControlValueAccessor } from '@angular/forms';
import { IEnSelectListItem } from './en-select-list-item.interface';
import { OffClickDirective } from './../directives';
const noop = () => {
};
export class EnSelectComponent implements OnInit {
private active: boolean = false;
private selectedOption: IEnSelectListItem;
private selectedSuboption: IEnSelectListItem;
options: IEnSelectListItem[];
placeholder: string;
label: string;
public element: ElementRef;
public constructor(element: ElementRef) {
this.element = element;
this.clickedOutside = this.clickedOutside.bind(this);
}
ngOnInit() {
}
private _close(){
if(this.active) {
this.active = false;
}
}
public clickedOutside():void {
this._close();
}
public selectOption(o: IEnSelectListItem) {
this.selectedOption = o;
this.selectedSuboption = null;
this._close();
}
public selectSuboption(o: IEnSelectListItem, so: IEnSelectListItem) {
this.selectedOption = o;
this.selectedSuboption = so;
this._close();
}
public toggleOpen(): void {
this.active = !this.active;
}
}