我需要在输入文本中添加百分比符号。
我所需要的就是这个(相同)
https://codepen.io/mesapkota/pen/bmoqzr
但在Angular 上。没有jquery。
这是我的项目
https://stackblitz.com/edit/percentage-directive-in-angular?file=src/app/app.component.html
<input type="textbox" [(ngModel)]="InputValue" placeholder="example 22.2" appPercentageDirective>
2条答案
按热度按时间798qvoo81#
您需要将keyup添加到输入中,每次将“%”替换为“”,然后再次添加。我认为您的代码应该如下所示:app.component.html
app.component.ts:
whlutmcx2#
我认为直接添加%是没有意义的,您可以在请求时添加它,如果您想显示页面,可以在css显示中使用伪元素,因此代码将更加灵活