我有一個非常奇怪的問題。我有一個輸入,我只想在輸入有值時顯示一個按鈕。只有當我移動滑鼠時它才有效。
<input class="form-control"
type="text"
placeholder="hello there..."
#helloInput
>
{{helloInput.value}} --> not shows until mouse is moving
<button class="btn btn-success"
*ngIf="helloInput.value"
>Show me</button>
這很奇怪。任何的想法?
uj5u.com熱心網友回復:
Angular 僅通過呼叫更改檢測來更新視圖。大多數情況下,由于事件偵聽器/XHR/setTimeout/setInterval 呼叫,它會自動發生。
在您的示例中,Angular 沒有已知的任何事件偵聽器。由于它是由 mousemove 更新的,因此它有一些偵聽器并且 Angular 檢測到了它。
為了在任何輸入值更改時更新您的視圖,您只需添加空input事件偵聽器:
<input class="form-control"
type="text"
placeholder="hello there..."
#helloInput
(input)="0" <=============== this one
>
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/372741.html
標籤:javascript 有角的 打字稿 数据绑定
上一篇:VS代碼設定中的三個點
