Added rxjs in packege.json; Added activateOnInputEvents proprierty for listen the events in input element and resize when it occurs
This commit is contained in:
parent
9dc59fd560
commit
c76d6dbb1a
2 changed files with 14 additions and 4 deletions
|
|
@ -8,15 +8,16 @@ export class Ng2FittextDirective implements AfterViewInit, OnInit {
|
|||
@Input('fittext') fittext: any;
|
||||
@Input('container') container: any;
|
||||
@Input('activateOnResize') activateOnResize: boolean;
|
||||
@Input('activateOnInputEvents') activateOnInputEvents: boolean;
|
||||
private fontSize: number = 0;
|
||||
private speed: number = 1.05;
|
||||
|
||||
constructor(public el: ElementRef, public renderer: Renderer) {
|
||||
}
|
||||
|
||||
|
||||
setFontSize(fontSize) {
|
||||
this.fontSize = fontSize;
|
||||
return this.el.nativeElement.style.setProperty('font-size', (fontSize).toString()+'px');
|
||||
this.fontSize = fontSize;
|
||||
return this.el.nativeElement.style.setProperty('font-size', (fontSize).toString()+'px');
|
||||
}
|
||||
|
||||
calculateFontSize(fontSize, speed){
|
||||
|
|
@ -38,6 +39,14 @@ export class Ng2FittextDirective implements AfterViewInit, OnInit {
|
|||
}
|
||||
}
|
||||
|
||||
@HostListener('input', ['$event'])
|
||||
onInputEvents() {
|
||||
if(this.activateOnInputEvents && this.fittext) {
|
||||
this.setFontSize(this.container.clientHeight);
|
||||
this.ngAfterViewInit();
|
||||
}
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
if (this.fittext) {
|
||||
this.setFontSize(this.container.clientWidth);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue