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

Чипсы

PrimeNG/Chips (opens in a new tab)

Чипсы используются для ввода нескольких значений в поле ввода.

С чего начать

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

import { ChipsModule } from 'primeng/chips';

В .ts файле

import { Component, OnInit } from '@angular/core';
 
@Component({
  selector: 'app-prime-chips',
  templateUrl: './prime-chips.component.html',
  styleUrls: ['./prime-chips.component.scss']
})
export class PrimeChipsComponent implements OnInit {
  valuesBasic: string[];
  valuesComma: string[];
  valuesTemplate: string[];
  valuesSizeLg: string[];
  valuesSizeMd: string[];
  valuesSizeSm: string[];
 
  constructor() { }
 
  ngOnInit(): void {
  }
 
}

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

Basic

Comma Separator

Template

item - (active)

Размеры

Float

Свойства

NameTypeDefaultDescription
fieldstringnullName of the property to display on a chip.
maxnumbernullMaximum number of entries allowed.
disabledbooleanfalseWhen present, it specifies that the element should be disabled.
stylestringnullInline style of the element.
styleClassstringnullStyle class of the element.
placeholderstringnullAdvisory information to display on input.
tabindexnumbernullIndex of the element in tabbing order.
inputIdstringnullIdentifier of the focus input to match a label defined for the component.
ariaLabelledBystringnullEstablishes relationships between the component and label(s) where its value should be one or more element IDs.
allowDuplicatebooleantrueWhether to allow duplicate values or not.
inputStylestringnullInline style of the input field.
inputStyleClassstringnullStyle class of the input field.
addOnTabbooleanfalseWhether to add an item on tab key press.
addOnBlurbooleanfalseWhether to add an item when the input loses focus.
separatorstringnullSeparator char to add an item when pressed in addition to the enter key. Currently only possible value is ","

События

NameParametersDescription
onAddoriginalEvent: Browser event<br>value: Added item valueCallback to invoke when a value is added.
onRemoveoriginalEvent: Browser event<br>value: Added item valueCallback to invoke when a value is removed.
onChipClickoriginalEvent: Browser event<br>value: Clicked item valueCallback to invoke when a chip is clicked.
onFocusoriginalEvent: Browser eventCallback to invoke when a input is focused.
onBluroriginalEvent: Browser eventCallback to invoke when a input loses focus.

Шаблоны

NameParameters
chip$implicit: value

Стилизация

NameElement
p-chipsContainer element.
p-chips-tokenChip element container.
p-chips-token-iconIcon of a chip.
p-chips-token-labelLabel of a chip.
p-chips-input-tokenContainer of input element.

Накладываение текста при предзаполненном p-chips

Такая ситуация в данный момент исправляется добавлением классаp-inputwrapper-filled, а лучше проверкой:

Также стоит изменить values

values = new BehaviorSubject(["Один", "Два", "Три"]);