ng-semantic
Version:
Angular2 building blocks based on Semantic UI
57 lines (49 loc) • 1.9 kB
text/typescript
import {
Component, Input, AfterViewInit, ViewChild, ElementRef, Output, EventEmitter, ChangeDetectionStrategy
} from "@angular/core";
import { FormControl } from "@angular/forms";
declare var jQuery: any;
export class SemanticSelectComponent implements AfterViewInit {
control: FormControl = new FormControl();
class: string;
label: string;
options: {} = {};
placeholder: string;
modelChange: EventEmitter<string|number> = new EventEmitter<string|number>();
onChange: EventEmitter<string|number> = new EventEmitter<string|number>();
select: ElementRef;
set model(data: string|number) {
if (data) {
setTimeout(() => {
jQuery(this.select.nativeElement).dropdown("set selected", data);
}, 1);
}
}
private multiple: boolean = false;
ngAfterViewInit(): void {
if (typeof this.class === "string" && this.class.search("multiple") >= 0) {
this.select.nativeElement.setAttribute("multiple", true);
}
const options: {} = Object.assign(this.options, {
onChange: (value: string|number) => {
this.onChange.emit(value);
this.modelChange.emit(value);
},
onHide: () => this.control.markAsTouched()
});
jQuery(this.select.nativeElement)
.dropdown(options);
}
}