Skip to content

Instantly share code, notes, and snippets.

View kylekarpack's full-sized avatar

Kyle kylekarpack

View GitHub Profile
@kylekarpack
kylekarpack / grow.directive.ts
Created August 23, 2019 17:50
ngx-textarea-grow
// Simplified combination of the following libraries:
// https://raw.githubusercontent.com/evseevdev/ngx-textarea-autosize/master/lib/src/autosize.directive.ts
// https://raw.githubusercontent.com/chrum/ngx-autosize/master/projects/autosize/src/lib/autosize.directive.ts
import { AfterViewInit, Directive, DoCheck, ElementRef, HostBinding, HostListener, Input, Renderer2 } from "@angular/core";
@Directive({
selector: "textarea[grow]"
})
export class GrowDirective implements AfterViewInit, DoCheck {
(function(){
var cache = {};
this.tmpl = function tmpl(str, data){
// Figure out if we're getting a template, or if we need to
// load the template - and be sure to cache the result.
var fn = !/\W/.test(str) ?
cache[str] = cache[str] ||
tmpl(document.getElementById(str).innerHTML) :