Angular mat-form-field not accepting placeholder value

It seems that the placeholder for input which reads "Search Here" is not functioning properly. Could it be because it's contained within a mat-form-field?

The only CSS rules defined for the input class are:

.search-input{
    width:100%;    
}

Any assistance on this matter would be greatly appreciated.

<mat-form-field   class="search"  floatLabel="never" >
        <mat-label for="search"></mat-label>
          <input class="search-input" matInput value=""  id="search" placeholder="Search here" name="search" type="text" (change)="inputChange($event)" [(ngModel)]="searchText" [matAutocomplete]="auto" (input)="onChange()">
          <mat-autocomplete #auto="matAutocomplete">
            <mat-option [hidden]="!showPeople"  (click)="submitSearch()" [value]="getFullName(user)" *ngFor="let user of persons"><mat-icon class="option">person</mat-icon>{{getFullName(user)}}</mat-option>
            <mat-option  [hidden]="!showEvents" (click)="submitSearch()" [value]="event.eventName"*ngFor="let event of events "><mat-icon class="option">event</mat-icon>{{event.eventName}}</mat-option>
          </mat-autocomplete>
          <button type="button" (click)="submitSearch()" mat-icon-button matSuffix class="search-button"><mat-icon><span style="font-weight: bolder;">search</span></mat-icon></button>
      </mat-form-field>

I have attempted various approaches to resolve this issue but none have proven successful.

Answer №1

I implemented a code snippet from the official documentation and it's functioning perfectly, feel free to check out my implementation

 <form class="example-form">
  <mat-form-field class="search" floatLabel="auto">
    <input
      class="search-input"
      matInput
      placeholder="Enter your search query"
      aria-label="Search here"
      type="text"
      [formControl]="myControl"
      [matAutocomplete]="auto"
    />
    <mat-autocomplete #auto="matAutocomplete">
      <mat-option
        *ngFor="let option of filteredOptions | async"
        [value]="option"
      >
        {{option}}
      </mat-option>
    </mat-autocomplete>
  </mat-form-field>
</form>

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

Tailored Bootstrap form styles for different screen sizes

Can someone please help me understand how to create a custom Bootstrap class that applies to a specific breakpoint? I've tried using w-md-50, w-sm-100, w-lg-75 for a form, but it doesn't seem to be working for the targeted breakpoint. Are there a ...

What is the reason for WordPress theme CSS and JS files loading after the head tag?

I'm experiencing an issue where my Wordpress theme's CSS and JS files are loading after the head tag. Additionally, when I view the source in Firefox, they are showing up in red, indicating incorrect markup. Can anyone help me figure out what&ap ...

Implementing an alert box upon redirect with PHP

This question is pretty straightforward. I have a form on my index.html page and PHP code to submit that form to an external URL, then redirect back to the index: <?php Echo "<style>body{background:#3e4744}</style>"; Echo "<style>h2{ ...

Preserving the video's aspect ratio by limiting the width and height to a maximum of 100%

I am trying to integrate a YouTube video using their embed code in a "pop-up". However, I am facing an issue where the video does not resize to fit within the height of its parent. I want it to be constrained by the div#pop-up that contains the video. Curr ...

Display content in two columns. If the width of the left column is too narrow, move the content in the right column

In my layout, there is a wrapper div with two child elements: left div and right div. The left div contains text which can be lengthy, while the right div holds an image loaded asynchronously without known width: <div id="wrapper"> <div id="l ...

Is your Node.js EventLoop operation stuck in limbo?

This pertains to a Node/Express/MongoDB application, involving an AJAX call Previously, the selector.html() event was updating the html content of the selector, but now it is not. The only modification made was the addition of an editAll() function in ...

Ensure the box remains unchecked if it is not enabled

I have implemented a tree table in my Angular application. Below is the code snippet: <h5>Checkbox Selection</h5> <p-treeTable [value]="files5" [columns]="cols" selectionMode="checkbox" [(selection)]=&qu ...

Executing dispatch Action in store.pipe of Angular 13 from within a component

I am currently working with Angular 13 and ngRxStore. Within my component, I am looking to access my store and trigger a new Action using the data retrieved from the store. Here is a snippet of my code: productState$ :Observable<ProductsState> | null ...

Switch out either even or odd divs within a container

I need help figuring out how to alternate the background colors of divs within a container. I want the first one to have a red background, the second to have blue, the third red again, and so on... Here is the code I currently have: <div>...</di ...

Tips for accurately documenting the Props parameter in a React component with Destructuring assignment

Attempting to create JSDocs for a React component using destructuring assignment to access props: const PostComponent: React.FC<IPostComponent> = ({ title, body }) => { ... } The issue arises when trying to document multiple parameters in JSDocs ...

Creating objects based on interfaces in TypeScript is a common practice. This process involves defining

Within my TypeScript code, I have the following interface: export interface Defined { 4475355962119: number[]; 4475355962674: number[]; } I am trying to create objects based on this interface Defined: let defined = new Defined(); defined['447 ...

Winston's createLogger function is not defined

After setting up Jest unit tests in a TypeScript Node project, I encountered an issue where the main code broke after installing Jest with ts-node. Whenever I try to run npm test or npm start, I receive the following error: [nodemon] watching extensions: t ...

What causes the collapse of text in neighboring rows?

I am struggling to display all the data in each column without using ellipsis. The data is getting collapsed with the adjacent row. I need a way to show the entire content of each column, even if it's large. Unfortunately, I don't know the exact ...

Utilizing Javascript Objects on Websites

Beginner's query: Even after researching extensively on various platforms like W3Schools and other websites, I am unable to find the solution I need. I am sure it is a simple fix for someone experienced like you. I am working with ASP.Net and wish t ...

In search of advice on the best web-based database management technology

I'm looking to create a prototype for a web-based database manager, similar to the desktop version in the image below, with specific features in mind. Initially, the schema will be provided through a flat file. Considering HTML5 as an option, I am a ...

The div containing the background image does not resize properly when using media queries

page in question. I am currently working on a chess board project where each cell is represented by a div element. My goal is to make the board expand beyond certain minimum widths using media queries, but for some reason, this functionality is not working ...

Disappear element after a brief moment

What is the best way to temporarily hide an element and then have it reappear after a second? var targetElement = document.getElementById("myElement"); targetElement.onclick = function() { this.style.display = "none"; setTimeout(function(){ ...

ways to run php script based on screen resolution or size

I have 2 php files that I need to execute based on screen size. include_once('large.php'); include_once('small.php'); The condition is to run large.php when the screen size is greater than 992px, and small.php when the screen size is ...

How come I am unable to alter the border color in the input field of material-ui?

My goal is to change the input border color to white regardless of whether it is focused, hovered, or just by default. I have attempted to create a theme using makeStyles for the text and input fields but it does not seem to be working. Here is my code: c ...

I encountered an error while conducting an Angular test - Failed: Unable to access the property 'className' as it is undefined

My spec.ts file is running fine with all test cases passing, but occasionally I encounter failures with the error message Failed: Cannot read property 'className' of undefined. This error seems to be related to the Syncfusion library I am using f ...