Angular keyup 事件处理如何帮助更新引用变量的值

how Angular keyup event handling helps updating reference variable's value

我是 Angular 的新手,我在 angular 文档中看到了这段代码:

 <input #box (keyup)="0">
    <p>{{box.value}}</p>

无论在 keyup 事件处理块中写了什么,它都应该被处理到 box.value 得到更新和下一行的字符串插值,{{box.value}},正常工作。我想知道这是如何工作的。

我相信这已经在docs中清楚地阐明了。

This won't work at all unless you bind to an event.

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.

也来自文档。

The template is completely self contained. It doesn't bind to the component, and the component does nothing.

因此,如果您没有明确告诉 Angular 检查值的变化(此处使用 keyup 事件),它就不会关心模板引用变量 #box .