Skip to content

Instantly share code, notes, and snippets.

@m-abs
Created May 7, 2018 16:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save m-abs/7743a0aa41621a5a54a74ef9d357e41b to your computer and use it in GitHub Desktop.
Save m-abs/7743a0aa41621a5a54a74ef9d357e41b to your computer and use it in GitHub Desktop.
NativeScript resize label on text change:
import { Directive, ElementRef, Input } from '@angular/core';
import { Label } from 'tns-core-modules/ui/label';
/**
* Make sure the layout is updated then the Label's text is changed.
*/
@Directive({
// tslint:disable-next-line:directive-selector
selector: 'Label[text]',
})
export class UpdateLabelDirective {
@Input('text')
public set _text(text: string) {
const nativeView = this.nativeView;
if (nativeView && nativeView instanceof Label) {
nativeView.text = text;
nativeView.requestLayout();
}
}
private get nativeView(): Label {
return this.el.nativeElement;
}
constructor(private readonly el: ElementRef) {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment