Angular html 页面里的井号 #

2021-12-03  本文已影响0人  华山令狐冲

例子:

<input #inp (change)="foo = inp.value">

listenes to the change event and calls onChange() and passes the inputs value property

监听 change 事件,通过 # 后面的名称,再加上 .value 获取 DOM 元素的输入值。
看下面这个例子:

<h1>Jerry</h1>
<input #inp (change)="foo = inp.value">
<div>{{ foo }}</div>

Component 里的定义:

最终效果:


更多Jerry的原创文章,尽在:"汪子熙":


上一篇 下一篇

猜你喜欢

热点阅读