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 里的定义:
![](https://img.haomeiwen.com/i2085791/1d5c39bcb7bcdd73.png)
最终效果:
![](https://img.haomeiwen.com/i2085791/36e648d59b44e140.png)
更多Jerry的原创文章,尽在:"汪子熙":
![](https://img.haomeiwen.com/i2085791/97c4752c0e619c44.png)