I want to change color chips in primeng,that whenever I select one I get a diffrent color!, can anyone help me how to do that!
my code :
<p-multiSelect [options]="cars" [(ngModel)]="selectedCars1" [selectionLimit]=3 [panelStyle]="{minWidth:'12em'}"
[maxSelectedLabels]=2></p-multiSelect>
<p>Selected Cars: </p>
<p-chips [(ngModel)]="selectedCars1" ></p-chips>
To add a different background to your PrimeNG chips, you can do the following,
Create an event handler for the
onAdd
event along with a function to select all elements in the document with the CSS selectorli.p-chips-token
. This function essentially helps in accessing all the PrimeNG chips.Since the requirement specifies that the background of each PrimeNG chip should differ, we would need to also create a function to generates random colors.
TLDR;
For your reference, please find link to a working demo here
Edit:
If your requirement was to only change the background color of the PrimeNG chip from the default background color, please do the following.
In your styles.css file,