Adding an Icon in p-autoComplete with PrimeNG in Angular 10

Is there a way to insert an icon within the primeng p-autoComplete component?

<div class="p-mr-2 p-input">
   <p-autoComplete styleClass="p-autocomplete-list-item" [(ngModel)]="location"
     [suggestions]="results" field="name" placeholder="Search location"> 
   </p-autoComplete>
 </div>

I am seeking a method to include a location icon within this auto-complete feature

Answer №1

PrimeNg offers the InputGroup feature that allows you to include an icon with an input field.

<div class="p-mr-2 p-input">
  <div class="p-inputgroup">
    <span class="p-inputgroup-addon">$</span>
    <p-autoComplete styleClass="p-autocomplete-list-item" [(ngModel)]="location [suggestions]="results" field="name" placeholder="Search location">
    </p-autoComplete>
  </div>
</div>

You can customize the icon by replacing the $ symbol with your desired location representation.

Answer №2

One of the properties available is called dropdownIcon, where you can specify an icon name, with a default value of "pi pi-chevron-down".

<p-autoComplete
              [group]="true"
              field="label"
              [multiple]="true"
              [dropdown]="true"
              dropdownIcon="pi pi-dropdown"
            >

Answer №3

Here's a suggestion for you to consider using different measurements:

<div
    id="searchGroup"
    class="inner-inline-group"
  >
    <i class="pi pi-search search-icon"></i>
    <p-autoComplete
      id="searchInput"
      [style]="{ width: '98%', position: 'static' }"
    ></p-autoComplete>
  </div>

For the component's css styling:

.search-icon {
  z-index: 1;
  position: relative;
  left: 41px;
  top: 9px;
  align-self: center;
}

In the global styles.css file:

 .p-autocomplete-input {
  padding-left: 33px;
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Can't decide between ngOnInit() and ngAfterContentInit()?

As a newcomer to Angular, I sometimes get confused about the ngOnInit() and ngAfterContentInit() lifecycle hooks. According to the official documentation: ngOnInit() : This hook is used to initialize the directive/component after Angular has displayed the ...

Sending an HTML variable to a different JavaScript file

A Python class has sent over a dictionary named "sentiments" to my HTML file. The code snippet below demonstrates how this dictionary is being utilized: {% if sentiments %} <p>{{sentiments}}</p> {% else %} <p>none</p> {%end ...

Encountering an issue with extending the MUI color palette, receiving a "reading 'dark'" error due to properties of undefined

Encountering an issue when trying to expand the MUI color palette—getting this error instead: Error: Cannot read properties of undefined (reading 'dark') Take a look at my theme.ts file below: const theme = createTheme({ palette: { pri ...

The active class in the Bootstrap carousel is not updating when trying to change

I am struggling to make the Twitter Bootstrap carousel function properly. Although the slides automatically change after the default timeout, the indicators do not switch the active class, resulting in my carousel failing to transition between slides. Ini ...

Error: the function method is not declared in the JavaScript/jQuery code

Within my main.js file, there is a method outlined as follows: ;(function ($, window, document, undefined) { 'use strict'; var testing = function(d) { //irrelevant code }; })(jQuery, window, document); In the HTML of my pr ...

Implementing text wrapping within input elements for optimal print.css layout

Can you help me with a print.css issue I'm experiencing? I am currently working on my print stylesheet and I've encountered a challenge where I need to word wrap input fields to ensure all the text is displayed correctly. Despite trying various ...

Error: The selectBox function is not defined for $(...)

Currently, I am encountering an issue with the code snippet below when attempting to select options from a dropdown: Uncaught TypeError: $(...).selectBox is not a function. This error message appears in the console. In order to resolve this problem, I ha ...

What are the HTML5 elements that include the "load event" within their onload attribute?

Mozilla's MDN provides information regarding the load Event with this brief explanation: The load event is triggered when a resource and its dependent resources have completed loading. and references standard 1, which states Trusted Targets: ...

JavaScript salary calculation function not functioning properly

Once the user inputs the employee's name and the number of hours they worked on the HTML form, the submit button captures this information and stores it in variables for calculating their pay. The script also factors in overtime pay. Despite feeling l ...

What advantages does NgRx offer that Signal does not provide?

Signals are a recent addition to the Angular framework. In comparison to Signals, what unique benefits does the NgRx component store or other state management options provide? Are there any functionalities offered by the NgRx component store that cannot ...

Encountering a glitch while iterating through function results in failure after the initial modification

I am facing some errors with the script provided below: var sections = ["#general_info", "#address_records", "#employment_history", "#driver_experience", "#military_experience", "#eeo_survey", &qu ...

When the page loads, the ASP menu should display the sub-menu items in a unique style

<asp:SiteMapDataSource runat="server" ID="RelativeSiteMapDataSource" StartFromCurrentNode="False" ShowStartingNode="False" SiteMapProvider="CatalogSiteMap" /> <asp:Menu runat="server" ID="Navigator" MaximumDynamicDisplayLevels="0" StaticDispl ...

What is the best way to keep the position of divs fixed when resizing the page?

I am currently designing a layout for a Tic Tac Toe game and I want the square blocks to remain in the same position even when the screen size is adjusted. The tools I am using are Bootstrap 4 and SCSS. 1) How can I ensure that the square blocks stay fix ...

To retrieve the specific section containing data and prevent any empty sections in Angular2

My section is populated with static data, but I am also getting an empty section. Can someone assist me in retrieving only the data and excluding the empty section? TS: this.Emergencies = [{ "ContactName": "Person1", "Phone": "12345678", "Relati ...

Placing an Image in the Right Corner Using jQuery Mobile

I am currently developing a mobile app and I need to align three images one below the other at the right corner next to some text. Any suggestions would be greatly appreciated. Thank you in advance. Below is my code snippet: <div> <ul data-r ...

Extracting text from an HTML comment tag using Google Apps Script

When utilizing Google Apps Script, I enjoy extracting ticker names into an array. Specifically, I am interested in capturing only the first text section before the first vertical bar in each line (for instance, extracting "TROW" from "TROW|222.38|27987" ...

I'm experiencing difficulty in loading a static HTML page from the app file when using Node.js

I'm currently working on setting up a system where an HTML page is loaded upon request to the app. Although I've managed to get the HTML to load successfully using res.end('') within the server definition, I find this method to be messy ...

Guide to aligning form data with Bootstrap

Struggling to align my form data in the center below. I have attempted various online solutions without success. The use of bootstrap and offset is causing issues with the title for the form and the actual form itself. Any suggestions would be highly appre ...

Adjust the cell text overflow based on the width of the table

I am working with a table that has multiple columns. I want the first 3 columns to have a larger width than the others, specifically taking up 15% each for a total of 45% of the table's width. Currently, I am using this code in a sandbox environment: ...

Adjusting Text Size Depending on Width

I recently used an online converter to transform a PDF into HTML. Check out the result here: http://www.example.com/pdf-to-html-converted-file The conversion did a decent job, but I'm wondering if it's feasible to have the content scale to 100% ...