The mat-selection-list fails to display within the mat-autocomplete menu

When developing a mat-autocomplete component to allow for multiple selections, I opted to utilize a mat-selection-list. This choice was made in order to take advantage of built-in features like checkboxes.

However, despite initializing the 'chartList' array with values, the dynamic mat-selection-list does not display within the mat-autocomplete component.

<mat-form-field>
    <mat-label>{{ Patient }}</mat-label>
    <input type="text" placeholder="Text" matInput formControlName="links" [matAutocomplete]="auto" />
    <mat-autocomplete #auto="matAutocomplete">
        <mat-selection-list #selectionList (selectionChange)="onSelectionChange($event)"  [disableRipple]="true">

            <mat-list-option *ngFor="let chart of chartList" [value]="chart"
                [checkboxPosition]="'before'" [id]="chart.key">
                <div class="d-flex">
                    <span class="col-4 xs-text">{{ chart.name }}</span>
                    <span class="col-3 xs-text">{{chart.additionalData.dateOfBirth | date}}</span>
                    <span class="col-4 xs-text">{{chart.additionalData.city }}</span>
                </div>
            </mat-list-option>
        </mat-selection-list>
    </mat-autocomplete>
  </mat-form-field>

Although the cdk-panel is visible as a slender dropdown, it appears empty without any content being displayed.

Answer №1

Upon careful examination of the Documentation, I hypothesized that this could be the solution.

It appeared that each option needed to be defined by a mat-option tag.

Although my initial assumption was to use a mat-selection-list as mentioned in the question. Moreover, it is explicitly stated as a should rather than a must.

Nevertheless, the following code snippet turned out to be the working solution:

<mat-form-field>
    <mat-label>{{ Patient }}</mat-label>
    <input type="text" placeholder="Text" matInput formControlName="links" [matAutocomplete]="auto" />
    <mat-autocomplete #auto="matAutocomplete">
        <mat-selection-list #selectionList (selectionChange)="onSelectionChange($event)"  [disableRipple]="true">

            <mat-list-option *ngFor="let chart of chartList" [value]="chart"
                [checkboxPosition]="'before'" [id]="chart.key">
                <div class="d-flex">
                    <span class="col-4 xs-text">{{ chart.name }}</span>
                    <span class="col-3 xs-text">{{chart.additionalData.dateOfBirth | date}}</span>
                    <span class="col-4 xs-text">{{chart.additionalData.city }}</span>
                </div>
            </mat-list-option>
        </mat-selection-list>

     <mat-option [style.display]="'none'"></mat-option>
    </mat-autocomplete>
  </mat-form-field>

Take note of the addition of an empty mat-option element.

I'm still uncertain why it's necessary...

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

This phrase cannot be invoked

My code seems correct for functionality, but I am encountering an error in my component that I do not know how to resolve. Can someone please help me with this issue? This expression is not callable. Not all constituents of type 'string | ((sectionNa ...

Styling with CSS in Angular 2+ can be quite challenging

Hey there, I'm new to Angular 4 and running into some troubles with styling my application. I tried adding a background image to the body, which worked fine, and then added a component to display content, also looking good. Now, when I added a second ...

Create a typescript class object

My journey with Typescript is just beginning as I delve into using it alongside Ionic. Coming from a background in Java, I'm finding the syntax and approach quite different and challenging. One area that's giving me trouble is creating new object ...

What is the process of transforming a Firebase Query Snapshot into a new object?

Within this method, I am accessing a document from a Firebase collection. I have successfully identified the necessary values to be returned when getUserByUserId() is invoked, but now I require these values to be structured within a User object: getUserB ...

An error has occurred in Node.js/Express.js: The path argument is missing and is required for res.sendFile

I have successfully uploaded my files using Multer to a specific directory. However, I am now facing an issue while trying to download the same files that are displayed in an HTML table with individual download options. Below is the code snippet: Node.j ...

"Encountered a TypeError while attempting to send a server action to a custom

My custom form component, <ClientForm>, is built using Radix Primitives. "use client"; import { FC } from "react"; import * as Form from "@radix-ui/react-form"; const ClientForm: FC = (props) => ( <Form.Root {.. ...

Controlling the visibility of components or elements in Angular through input modifications

Is there a more efficient way to handle button disabling and enabling based on email validation in Angular? I already have form controls set up, but want to make the process cleaner. The goal is to disable the "Get Started" button by default if the email a ...

How come once I close a PrimeNG modal that is defined within a child component, I am unable to reopen it?

Currently, I am developing an Angular application that utilizes PrimeNG. In the process, I encountered a challenge. Initially, I had a component with a PrimeNG Dialog embedded within (refer to this link), and it was functioning properly. To streamline my ...

Encountered an issue while trying to add @angular/fire to the project - unable to resolve

Having encountered some issues with the commands I used in these versions. Can anyone provide assistance in resolving this matter? Your help is greatly appreciated. ------------------------------------------- Angular CLI: 14.0.0 Node: 16.15.1 Package ...

Steps for transforming a regular string into a template string

Consider the following scenario: var data = '{"message": "`${message}`"}'; var obj = JSON.parse(data); var templateValue = obj.message; //`${message}` var message = 'hello'; What is the best way to evaluate the ...

Injecting AngularJS together with TypeScript and Restangular to optimize application performance

Encountering an issue while trying to configure my angularjs + typescript application with the restangular plugin Here are the steps I have taken: Ran bower install --save restangular (now I have in index.html <script src="bower_components/restang ...

Access the most up-to-date information through the API URL

Objective: Whenever the 'Test' Button is clicked, new data must be fetched from the backend using the API link and displayed on the modal form. Issue: If text in the input box is changed or deleted, then the modal is closed and the 'Tes ...

The mat-dialog component in Angular does not apply the styling of mat-button

I'm facing an issue with my Angular 9 project. Everything seems to be working fine, except when a mat-dialog is opened, the buttons inside it do not have the material-style applied. Strangely, this problem only occurs within the mat-dialog window. On ...

Exploring the keyof feature in Typescript for array values

My issue involves managing a list export const list = [ { name: 'parentTitle', }, { name: 'anotherTitle', }, { name: 'whatever', }, ]; My goal is to dynamically create a union type that reflects the t ...

What are some best practices for managing object-level variables in TypeScript and Vue.js?

Uncertain about the optimal approach, I am looking to create a component and leverage some object level variables. Consider the example below: import Vue from "vue" import * as paper from "paper" export default Vue.extend({ template: ` <d ...

"What could be causing my React Native app to build without any issues even though the TypeScript compiler is throwing

Recently, I decided to explore TypeScript in combination with Expo. I took the time to set up linter and formatter integrations like typescript-eslint to help me catch errors while coding. Periodically, I run npx tsc to ensure my code compiles correctly an ...

Using *ngIf can lead to a never-ending cycle that never gets resolved

I am currently working on a project using Angular and I need to conditionally display a form based on certain values. I have successfully tested the backend route using Postman and everything is functioning correctly. Here is a snippet of my code: Block ...

"This error message states that the use of an import statement outside a module is not allowed

After searching for a solution without any luck, I decided to start a new discussion on this topic. Currently, I am working on azure functions using Typescript and encountering the following error: import { Entity, BaseEntity, PrimaryColumn, Column, Many ...

Vue 3 app encountering error due to element having an 'any' type implicitly

I want to incorporate lucidev icons into my component, but I am fairly new to typescript. You can find the lucidev icons here: https://github.com/lucide-icons/lucide <template> <component :is="icon" /> </template> <script ...

Tips for utilizing import alongside require in Javascript/Typescript

In my file named index.ts, I have the following code snippet: const start = () => {...} Now, in another file called app.ts, the code is as follows: const dotenv = require('dotenv'); dotenv.config(); const express = require('express' ...