redoc/lib/shared/components/DropDown/drop-down.ts

38 lines
840 B
TypeScript
Raw Permalink Normal View History

2016-04-19 18:50:01 +03:00
'use strict';
2017-01-26 19:21:24 +03:00
import { Component, EventEmitter, ElementRef, Output, Input, AfterContentInit, OnChanges } from '@angular/core';
2016-08-28 21:46:10 +03:00
import * as DropKick from 'dropkickjs';
2016-04-19 18:50:01 +03:00
@Component({
selector: 'drop-down',
templateUrl: 'drop-down.html',
styleUrls: ['./drop-down.css']
2016-04-19 18:50:01 +03:00
})
2017-01-26 19:21:24 +03:00
export class DropDown implements AfterContentInit, OnChanges {
@Output() change = new EventEmitter();
2017-01-26 19:21:24 +03:00
@Input() active: string;
elem: any;
inst: any;
constructor(elem:ElementRef) {
2016-04-19 18:50:01 +03:00
this.elem = elem.nativeElement;
}
ngAfterContentInit() {
2016-06-06 19:32:20 +03:00
this.inst = new DropKick(this.elem.firstElementChild, {autoWidth: true});
2016-04-19 18:50:01 +03:00
}
onChange(value) {
this.change.next(value);
}
2017-01-26 19:21:24 +03:00
ngOnChanges(ch) {
if (ch.active.currentValue) {
this.inst && this.inst.select(ch.active.currentValue);
}
}
2016-04-19 18:50:01 +03:00
destroy() {
this.inst.dispose();
}
}