To bind to a DOM event, surround the DOM event name in parentheses and assign a quoted template statement to it.
文法:将dom事件的名稱用圓括号包裹起來,再附上一個加上了雙引号的模闆聲明。
例子:
Click me!
看另一個例子:
Jerry Template reference variable test
{{box.value}}
1
2
3
運作效果:
當使用者在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架構隻有當應用響應某些同步或者異步事件,比如鍵盤敲擊,滑鼠點選時