问题
How can I enforce user to enter only numbers using p-chips
component?
I want to fill array of numbers
from user input.
Is there any alternative way to achieve this other than p-chips
component?
回答1:
By using p-chips
component, you can use onAdd
method to check user input :
HTML
<p-chips [(ngModel)]="values" (onAdd)=checkInput($event)></p-chips>
TS
checkInput(event) {
this.errorMessage = ''; // reinitialize error message
if(!this.isInt(event.value)) {
this.errorMessage = event.value + ' is not an integer !'; // display error message
this.values.pop(); // remove last entry from values
}
}
See Plunker
来源:https://stackoverflow.com/questions/49792210/prime-ng-p-chips-numbers-only-for-array-of-numbers