Prime-NG P-CHIPS Numbers only for Array of Numbers

*爱你&永不变心* 提交于 2021-01-05 07:27:20

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!