[英]How to set value to angular input
嗨,我正在嘗試將值設置為角度輸入框,但是當我這樣做時
let input = document.getElementById('mat-input-0');
input.value = "Something"
網站上的輸入框值會發生變化,但當我嘗試點擊按鈕並設置表單時,angular 看不到任何值
您可以綁定到輸入值屬性:
<input [value]="value">
或使用@ViewChild
獲取 TS 文件中的@ViewChild
:
html:
TS:
@ViewChild('input', { static: false }) input: ElementRef;
AfterViewInit() {
// Change the value here
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.