Skip to content

Instantly share code, notes, and snippets.

@salmanx
Last active November 23, 2017 07:37
Show Gist options
  • Save salmanx/fea790b29266c589b0b42166c48677a8 to your computer and use it in GitHub Desktop.
Save salmanx/fea790b29266c589b0b42166c48677a8 to your computer and use it in GitHub Desktop.
A simple angular directive to expand input field
import { Directive, ElementRef, Renderer } from '@angular/core';
@Directive({
selector: '[autoGrow]',
host: {
'(focus)' : 'onFocus()',
'(blur)' : 'onBlur()'
}
})
export class AutoGrowDirective {
constructor(
private el: ElementRef,
private render: Renderer
) { }
onFocus(){
this.render.setElementStyle(this.el.nativeElement, 'width', '300');
}
onBlur(){
this.render.setElementStyle(this.el.nativeElement, 'width', '150');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment