1 import { Component, ViewChild, ElementRef } from '@angular/core';
2 import { FieldType, FieldTypeConfig } from '@ngx-formly/core';
5 selector: 'cd-formly-textarea-type',
6 templateUrl: './formly-textarea-type.component.html',
7 styleUrls: ['./formly-textarea-type.component.scss']
9 export class FormlyTextareaTypeComponent extends FieldType<FieldTypeConfig> {
10 @ViewChild('textArea')
11 public textArea: ElementRef<any>;
14 const value = this.textArea.nativeElement.value;
16 const formatted = JSON.stringify(JSON.parse(value), null, 2);
17 this.textArea.nativeElement.value = formatted;
18 this.textArea.nativeElement.style.height = 'auto';
19 const lineNumber = formatted.split('\n').length;
20 const pixelPerLine = 25;
21 const pixels = lineNumber * pixelPerLine;
22 this.textArea.nativeElement.style.height = pixels + 'px';