Компоненты PrimeNG
InputMask

Инпут с маской

PrimeNG/InputMask (opens in a new tab)

Компонент InputMask используется для ввода данных в определенном формате, таком как число, дата, валюта и телефон.

С чего начать

Подключите модуль

import { InputMaskModule } from 'primeng/inputmask';

В .ts файле

import { Component, OnInit } from '@angular/core';
 
@Component({
  selector: 'app-prime-inputmask',
  templateUrl: './prime-inputmask.component.html',
  styleUrls: ['./prime-inputmask.component.scss']
})
export class PrimeInputmaskComponent implements OnInit {
 
  val1: string;
  val2: string;
  val3: string;
  val4: string;
  val5: string;
  val6: string;
 
  constructor() { }
 
  ngOnInit(): void {
  }
 
}

Встройте компонент с помощью тэга p-inputMask.

<p-inputMask mask="99-999999" [(ngModel)]="val1" placeholder="99-999999"></p-inputMask>

InputMask

Basic SSN Date Phone PhoneExt SerialNumber

Float Label

Свойства

NameTypeDefaultDescription
typestringtextHTML5 input type
maskstringnullMask pattern.
slotCharstring_Placeholder character in mask, default is underscore.
autoClearbooleantrueClears the incomplete value on blur.
unmaskbooleanfalseDefines if ngModel sets the raw unmasked value to bound value or the formatted mask value.
stylestringnullInline style of the input field.
styleClassstringnullStyle class of the input field.
placeholderstringnullAdvisory information to display on input.
sizenumbernullSize of the input field.
maxlengthnumbernullMaximum number of character allows in the input field.
tabindexnumbernullSpecifies tab order of the element.
disabledbooleanfalseWhen present, it specifies that the element value cannot be altered.
readonlybooleanfalseWhen present, it specifies that an input field is read-only.
namestringnullName of the input field.
inputIdstringnullIdentifier of the focus input to match a label defined for the component.
requiredbooleanfalseWhen present, it specifies that an input field must be filled out before submitting the form.
characterPatternstring[A-Za-z]Regex pattern for alpha characters
autoFocusbooleanfalseWhen present, the input gets a focus automatically on load.
autocompletestringnullUsed to define a string that autocomplete attribute the current element.
ariaLabelstringnullUsed to define a string that labels the input element.
ariaRequiredbooleanfalseUsed to indicate that user input is required on an element before a form can be submitted.
titlestringnullTitle text of the input text.

События

NameParametersDescription
onFocusevent: Browser eventCallback to invoke when input receives focus.
onBlurevent: Browser eventCallback to invoke when input loses focus.
onComplete-Callback to invoke on when user completes the mask pattern.
onInput-Callback to invoke on when the input field value is altered.
onKeydownevent: KeyboardEventCallback to invoke on when the input receives a keydown event.

Методы

NameParametersDescription
focus-Applies focus to the input.