Model to watch #10

Merged
martinduris merged 4 commits from master into master 2017-08-02 20:09:28 +00:00
martinduris commented 2017-08-02 14:29:21 +00:00 (Migrated from github.com)

Hi guys,
PR - introduced model (property for directive - modelToWatch), when model change -> font size will be recalculated (resolve #8 ).

Example usage :

<h1 [fittext]="true"[activateOnResize]="true" [useMaxFontSize]="true" [modelToWatch]="book?.title">
   {{book?.title}}
</h1>

Where 'book' is property which is "catched" from some backend (so it is loaded after some time ...).

Also created 'minFontSize' parameter with default value 7 (resolve #9 ).


! there is one thing which i do not like very much ...
setTimeout(_ => this.ngAfterViewInit() );

Explanation :
When model is changed -> method 'checkOverflow' is called -> BUT width / height of children / parent has old values (for example, in case of first load everything can be 0 -> because no text has been added to element).

After reading some articles (https://stackoverflow.com/questions/38930183/angular2-expression-has-changed-after-it-was-checked-binding-to-div-width-wi) - it seem like it is nothing special and usage of setTimeout is quite normal.

Please, if you have any ideas, feel free to contribute :-)

Martin

Hi guys, PR - introduced model (property for directive - **modelToWatch**), when model change -> font size will be recalculated (resolve #8 ). Example usage : ``` <h1 [fittext]="true"[activateOnResize]="true" [useMaxFontSize]="true" [modelToWatch]="book?.title"> {{book?.title}} </h1> ``` Where 'book' is property which is "catched" from some backend (so it is loaded after some time ...). Also created **'minFontSize'** parameter with default value 7 (resolve #9 ). ---------- ! there is one thing which i do not like very much ... **setTimeout(_ => this.ngAfterViewInit() );** **Explanation :** When **model is changed** -> **method 'checkOverflow' is called** -> BUT width / height of children / parent **has old values** (for example, in case of first load everything can be 0 -> because no text has been added to element). After reading some articles (https://stackoverflow.com/questions/38930183/angular2-expression-has-changed-after-it-was-checked-binding-to-div-width-wi) - it seem like it is nothing special and usage of **setTimeout** is quite normal. Please, if you have any ideas, feel free to contribute :-) Martin
thisloke commented 2017-08-02 20:11:56 +00:00 (Migrated from github.com)

Thanks a lot for your improvements :D

About setTimeout: i don't think it's bad as you used it, for sure it depends on the framework logic but i don't see, for now, alternatives.

Thanks a lot for your improvements :D About setTimeout: i don't think it's bad as you used it, for sure it depends on the framework logic but i don't see, for now, alternatives.
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: loke/ng2-fittext#10
No description provided.