Added resize on contentViewChanged hook

This commit is contained in:
Lorenzo Iovino 2017-08-11 12:17:03 +02:00
parent 7106f1df24
commit 1c87abbf2a
2 changed files with 8 additions and 3 deletions

View file

@ -1,6 +1,6 @@
{ {
"name": "ng2-fittext", "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.", "description": "An Angular2 directive for autoscale the font size of an element to fit an upper level container.",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {

View file

@ -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({ @Directive({
selector: '[fittext]' selector: '[fittext]'
}) })
export class Ng2FittextDirective implements AfterViewInit, OnInit, OnChanges { export class Ng2FittextDirective implements AfterViewInit, OnInit, OnChanges, AfterViewChecked {
@Input('fittext') fittext: any; @Input('fittext') fittext: any;
@Input('activateOnResize') activateOnResize: boolean; @Input('activateOnResize') activateOnResize: boolean;
@ -101,4 +101,9 @@ export class Ng2FittextDirective implements AfterViewInit, OnInit, OnChanges {
setTimeout(_ => this.ngAfterViewInit() ); setTimeout(_ => this.ngAfterViewInit() );
} }
} }
ngAfterViewChecked() {
this.setFontSize(this.container ? this.container.clientWidth : this.el.nativeElement.parentElement.clientWidth);
this.ngAfterViewInit();
}
} }