我只想用一个模板变量(引用) textarea显示editor中的字符数。
我的伪代码:
<p>{{editor.textarea.length}</p>
<div>
<textarea name="" id="" cols="30" rows="10" #editor></textarea>
</div>我知道我们可以用下面的方法来解决这个问题,但这不是我想要的。
export class AppComponent {
desc:string = "";
}和
<textarea [(ngModel)]="desc"></textarea>
<div>{{desc.length}}</div>问题:
如何用模板变量显示textarea中的字符数(没有@ViewChild )?
发布于 2022-08-18 07:12:30
将textarea替换为value,并在html标记中添加(keyup)="null"
<p>{{editor.value.length}}</p>
<div>
<textarea name="" id="" cols="30" rows="10" (keyup)="null" #editor></textarea>
</div>Stackblitz:示例
https://stackoverflow.com/questions/73393242
复制相似问题