簡體   English   中英

無法使用指令更改文本區域的Angular 5值

[英]Angular 5 value of text area can't be changed with directive

這是HTML:

<textarea expandTextArea class="form-control rounded-0" placeholder="What's on 
your mind, {{ UserInfo.firstname }}?" name="postbody"></textarea>

這是打字稿代碼:

@Directive({
    selector: '[expandTextArea]'
})
export class ExpandTextAreaDirective { 

    constructor() {}

    x: number = 0;

    @HostBinding('value') text: string = '';

    @HostBinding('rows') numRows: number = 2;

    @HostListener('focus') onFocus(eventData: Event) {
        this.numRows = 5;
    }

    @HostListener('blur') onBlur(eventData: Event) {
        this.numRows = 2;
        console.log(this.text);

    }
}

為什么控制台日志命令始終不將任何內容顯示為文本區域的值,除非將文本初始化為其他內容,但即使這樣它仍然不會更改。

因為textarea文本最初是空的。 嘗試在textarea標記中添加text = {{UserInfo.firstname}},並檢查console.log是否顯示文本UserInfo.firstname。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM