nts-ng2-components
Version:
Paquete de componentes para Angular2 desarrollado por NITSNETS.
41 lines (32 loc) • 1.16 kB
text/typescript
import { EventEmitter, Input, OnInit, Output } from '@angular/core';
import { Observable, Subscription } from 'rxjs/Rx';
import { NtsBaseComponent } from './base.component';
export abstract class NtsInputBaseComponent extends NtsBaseComponent implements OnInit {
ntsModel;
ntsModelChange = new EventEmitter();
ntsFocus = new EventEmitter();
ntsBlur = new EventEmitter();
name = '';
value = '';
required = false;
debounce = 0;
debounceSubs: Subscription;
ngOnInit() {
if (!this.ntsModel && this.value) {
this.onNgModelChange(this.value);
} else {
this.value = this.ntsModel;
}
}
onNgModelChange(ev): Observable<any> {
if (this.debounceSubs && !this.debounceSubs.closed) {
this.debounceSubs.unsubscribe();
}
const observable = Observable.timer(this.debounce || 0).share();
this.debounceSubs = observable.subscribe(_ => {
this.ntsModel = ev;
this.ntsModelChange.emit(ev);
});
return observable;
}
}