Fixed ngAfterwViewChecked, now compute size with height instead width

This commit is contained in:
Lorenzo Iovino 2017-08-11 14:15:31 +02:00
parent fc5e5e800f
commit 14a7091b53
2 changed files with 6 additions and 4 deletions

View file

@ -1,6 +1,6 @@
{
"name": "ng2-fittext",
"version": "1.0.22",
"version": "1.0.23",
"description": "An Angular2 directive for autoscale the font size of an element to fit an upper level container.",
"main": "index.js",
"scripts": {

View file

@ -86,7 +86,7 @@ export class Ng2FittextDirective implements AfterViewInit, OnInit, OnChanges, Af
}
} else {
if (this.useMaxFontSize) {
if(this.fontSize > this.maxFontSize) {
if (this.fontSize > this.maxFontSize) {
this.maxFontSize = parseInt(window.getComputedStyle(this.container ? this.container : this.el.nativeElement.parentElement).fontSize, null);
this.setFontSize(this.maxFontSize);
}
@ -103,7 +103,9 @@ export class Ng2FittextDirective implements AfterViewInit, OnInit, OnChanges, Af
}
ngAfterViewChecked() {
this.setFontSize(this.container ? this.container.clientWidth : this.el.nativeElement.parentElement.clientWidth);
if (this.fontSize > this.minFontSize) {
this.setFontSize(this.container ? this.container.clientHeight : this.el.nativeElement.parentElement.clientHeight);
this.ngAfterViewInit();
}
}
}