Prime-NG P-CHIPS 数字仅适用于数字数组

Kis*_*ash 5 primeng angular

如何强制用户使用p-chips组件仅输入数字?

numbers我想从用户输入中填充数组。

除了组件之外还有其他方法可以实现这一目标吗p-chips

Ant*_*ppe 7

通过使用p-chips组件,您可以使用onAdd方法来检查用户输入:

超文本标记语言

<p-chips [(ngModel)]="values" (onAdd)=checkInput($event)></p-chips>
Run Code Online (Sandbox Code Playgroud)

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
    }
  }
Run Code Online (Sandbox Code Playgroud)

参见普朗克