Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular Can´;无法从Ionic2中的ElementRef.nativeElement获取属性_Angular_Typescript_Ionic2 - Fatal编程技术网

Angular Can´;无法从Ionic2中的ElementRef.nativeElement获取属性

Angular Can´;无法从Ionic2中的ElementRef.nativeElement获取属性,angular,typescript,ionic2,Angular,Typescript,Ionic2,首先我要解释我想做什么。我在表单中有一个ion文本区域,我想根据内容调整高度。我还是一个ionic2的新手,我正在努力做正确的事情并学习,所以我认为最好的方法是创建一个指令,然后在ion textarea中使用它 基本上我需要的是: -从textarea -将textareaheight设置为scrollHeight值 我知道如何使用渲染器设置高度值,我的问题是获取scrollHeight(或任何其他属性值) 这是我的测试代码: import {Directive, ElementRef, Re

首先我要解释我想做什么。我在表单中有一个
ion文本区域
,我想根据内容调整高度。我还是一个ionic2的新手,我正在努力做正确的事情并学习,所以我认为最好的方法是创建一个指令,然后在
ion textarea
中使用它

基本上我需要的是: -从
textarea
-将
textarea
height设置为
scrollHeight

我知道如何使用渲染器设置高度值,我的问题是获取scrollHeight(或任何其他属性值)

这是我的测试代码:

import {Directive, ElementRef, Renderer} from '@angular/core';
@Directive({
    selector: '[textarea-autosize]',
})

export class TextareaAutosize{


    private el: HTMLElement;
    constructor(private element:ElementRef, private render:Renderer){
    }
    ngAfterViewInit(){

        this.el = this.element.nativeElement.querySelector('textarea'); //I have checked without querySelector too
        console.log(this.element.nativeElement.style); //this return CSSStyleDeclaration with all empty properties 
        console.log(this.el.scrollHeight); //this return always 0
        console.log(this.el); //this return the html textarea code
        this.render.setElementStyle(this.el, 'height', 100 + 'px'); //this set height to 100px
    }
}
我在谷歌上搜索了很多,我发现人们都像我一样有属性,因此,我做错了什么,或者我想用另一种方式来做什么