From 14a7091b5385460b1f4c810ff6143bb010144ec5 Mon Sep 17 00:00:00 2001 From: Lorenzo Iovino Date: Fri, 11 Aug 2017 14:15:31 +0200 Subject: [PATCH] Fixed ngAfterwViewChecked, now compute size with height instead width --- package.json | 2 +- src/ng2fittext.directive.ts | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index cfba17a..267a6be 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/ng2fittext.directive.ts b/src/ng2fittext.directive.ts index 7b2207b..e38c07d 100644 --- a/src/ng2fittext.directive.ts +++ b/src/ng2fittext.directive.ts @@ -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); - this.ngAfterViewInit(); + if (this.fontSize > this.minFontSize) { + this.setFontSize(this.container ? this.container.clientHeight : this.el.nativeElement.parentElement.clientHeight); + this.ngAfterViewInit(); + } } }