So what I am trying to achieve is very simple. Have an icon along with text. Below is what I want to achieve.
I am using PrimeNg
library in my Angular
application.
Dependencies
"@angular/cdk": "^11.1.0",
"@angular/common": "~11.0.5",
"@angular/compiler": "~11.0.5",
"@angular/core": "~11.0.5",
"primeng": "^11.2.0",
Below is my code which is pretty straightforward.
<p-dropdown
class="my-student-selector"
[options]="filters"
optionLabel="label"
placeholder="Filtres"
>
</p-dropdown>
Things I have tried.
- Used CSS
before/after
selector to add the icon. But there seems to be spacing issue which I tried to fix viacontent
but I guess I am missing something.
.p-placeholder::before {
background: url("/assets/images/icons/filter_icon.png");
// content: "''";
content: "\00a0 \00a0 \00a0 \00a0 \00a0 \00a0 \00a0 \00a0 \00a0 \00a0 \00a0 \00a0";
height: 16px; /*height of image*/
width: 14px;
position: absolute;
background-size: 16px 14px;
background-repeat: no-repeat;
padding-right: 5px;
}
- Used html directly in the placeholder attribute but as expected it just renders the html as string.
<p-dropdown
class="my-student-selector"
[options]="filters"
optionLabel="label"
placeholder="<span>Filtre</span>"
>
</p-dropdown>
- Used a variable to render the HTMl but same output. It renders HTML as string.
<p-dropdown
class="my-student-selector"
[options]="filters"
optionLabel="label"
[placeholder]="placeholder"
>
</p-dropdown>
placeholder = '<span style="color: gray">Select an option</span>';
- Used
pTemplate="placeholder"
attribute inside thep-dropdown
but I guess I am not using it write because this renders the option instead on placeholder
<p-dropdown
class="my-student-selector"
[options]="filters"
optionLabel="label"
>
<ng-template pTemplate="placeholder">
<span style="color: gray">Select an option</span>
</ng-template>
</p-dropdown>
Maybe I am not using the library correctly? Or missing some documentation.