我試圖使用pipe.Transform()
方法將百分號追加到文本框中的數字。如何在html輸入類型文本中添加%符號
<Input type="text" [(ngModel)]="value">
let test=12345;
this.value=this.percentPipe.transform(test,'1.0-3');
我可以用這個方法只需添加%
符號,而轉變呢?
我試圖使用pipe.Transform()
方法將百分號追加到文本框中的數字。如何在html輸入類型文本中添加%符號
<Input type="text" [(ngModel)]="value">
let test=12345;
this.value=this.percentPipe.transform(test,'1.0-3');
我可以用這個方法只需添加%
符號,而轉變呢?
如果使用角材料,然後就可以簡單地在輸入加後綴。
例子:
<form class="example-form">
<md-input-container class="example-full-width">
<input type="number" mdInput>
<span mdSuffix *ngIf="showPercentSymbol">%</span>
</md-input-container>
</form>
鏈接到這裏的文檔:https://material.angular.io/components/input/overview
好吧,但這會每隔一段時間出現。如果我想在特殊情況下使用它,我必須在component中寫入一些東西。這不會正常工作嗎? – TechnoSavvy
您可以在後綴範圍上添加條件。查看更新後的答案。 – Faisal
請提供的代碼演示您嘗試來完成你試過了,什麼什麼,並在那裏你失敗了。 –