'Clear trailing spaces after pasted number in Angular
How do we strip out spaces at the end of the 10digit number when user copies it from place (like email or word docs etc) and pastes it in the search bar?
But this function is only working when we hit enter. I want blank spaces to be removed as soon as we paste number.
public onSearchPolicy( event: any){
let search policy number= event.target?.value?.trim();
if ( searchPolicyNumber){
let searchPolicyObject = {
policy : searchPolicyNumber,}};
Solution 1:[1]
Great question, just keep it simple and:
- Get the element your pasting it in
document.getElementById
or however your binding it in Angular (@ViewChild
, etc).
- Then remove the spaces -
yourElementText.trim()
Solution 2:[2]
You could apply your function when the search input change.
.html
<input (ngModelChange)="onSearchChange()" />
.ts
onSearchChange() {
// Your code
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | jburtondev |
Solution 2 | Arthur PĂ©rez |