日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

Angular如何响应DOM event

發布時間:2023/12/19 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Angular如何响应DOM event 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

To bind to a DOM event, surround the DOM event name in parentheses and assign a quoted template statement to it.

語法:將dom事件的名稱用圓括號包裹起來,再附上一個加上了雙引號的模板聲明。

例子:

<button (click)=“onClickMe()”>Click me!

看另一個例子:

<h3>Jerry Template reference variable test</h3><input #box (keyup)="0"><p>{{box.value}}</p>

運行效果:

當用戶在input字段輸入值時,輸入值會自動出現在input element正下方的p element里。

然而template reference變量#box之后的 (keyup)="0"的含義是什么?

Angular updates the bindings (and therefore the screen) only if the app does something in response to asynchronous events, such as keystrokes. This example code binds the keyup event to the number 0, the shortest template statement possible. While the statement does nothing useful, it satisfies Angular’s requirement so that Angular will update the screen.

原來,Angular框架只有當應用響應某些同步或者異步事件,比如鍵盤敲擊,鼠標點擊時才會更新綁定信息進而刷新屏幕。因此為了使上面的例子能夠工作,需要將keyup事件綁定到一個template statement上,即使該statement不做任何事情,即最簡單的"0".

總結

以上是生活随笔為你收集整理的Angular如何响应DOM event的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。