diff --git a/package.json b/package.json index e08ff7c..cfba17a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ng2-fittext", - "version": "1.0.21", + "version": "1.0.22", "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 7263b01..c215282 100644 --- a/src/ng2fittext.directive.ts +++ b/src/ng2fittext.directive.ts @@ -1,9 +1,9 @@ -import {Directive, ElementRef, Renderer, Input, AfterViewInit, HostListener, OnInit, OnChanges, SimpleChanges} from '@angular/core'; +import {Directive, ElementRef, Renderer, Input, AfterViewInit, AfterViewChecked, HostListener, OnInit, OnChanges, SimpleChanges} from '@angular/core'; @Directive({ selector: '[fittext]' }) -export class Ng2FittextDirective implements AfterViewInit, OnInit, OnChanges { +export class Ng2FittextDirective implements AfterViewInit, OnInit, OnChanges, AfterViewChecked { @Input('fittext') fittext: any; @Input('activateOnResize') activateOnResize: boolean; @@ -101,4 +101,9 @@ export class Ng2FittextDirective implements AfterViewInit, OnInit, OnChanges { setTimeout(_ => this.ngAfterViewInit() ); } } + + ngAfterViewChecked() { + this.setFontSize(this.container ? this.container.clientWidth : this.el.nativeElement.parentElement.clientWidth); + this.ngAfterViewInit(); + } }