The Angular Material Autocomplete component fails to show items upon upgrading the angular/material package to the newest version

Issue with Angular Material Autocomplete component not displaying items after updating angular/material package to the latest version.

The autocomplete was functioning correctly with "@angular/material": "^2.0.0-beta.10" but encountered issues when updated to beta.11 version.

.html

<form class="example-form">
  <mat-form-field class="example-full-width">
    <input placeholder="Pick one"  matInput [formControl]="myControl" [matAutocomplete]="auto">
    <mat-autocomplete #auto="matAutocomplete">
      <mat-option *ngFor="let option of options" [value]="option">
        {{ option }}
      </mat-option>
    </mat-autocomplete>
  </mat-form-field>
</form>

.ts

import {Component} from '@angular/core';
import {FormControl} from '@angular/forms';

/**
 * @title Simple autocomplete
 */
@Component({
  selector: 'autocomplete-simple-example',
  templateUrl: 'autocomplete-simple-example.html',
  styleUrls: ['autocomplete-simple-example.css']
})
export class AutocompleteSimpleExample {

  myControl: FormControl = new FormControl();

  options = [
    'One',
    'Two',
    'Three'
   ];

}

Answer №1

To utilize the mat- prefix, it is essential to implement this initial step. You can find more information by visiting the following link: https://github.com/angular/material-prefix-updater#after-running-the-tool

import {MATERIAL_COMPATIBILITY_MODE} from '@angular/material';

@NgModule({
  providers: [
    {provide: MATERIAL_COMPATIBILITY_MODE, useValue: true},
    // ...
  ],
})
export class MyModule { }

Upon testing your code snippet with beta.11, errors were encountered in mat-form-field, matAutoComplete, mat-autocomplete, mat-option. Only matInput compiled without issues. The alternative snippet provided below compiles error-free.

C1

<form class="example-form">
  <md-form-field class="example-full-width">
    <input placeholder="Pick one" matInput [formControl]="myControl" [mdAutocomplete]="auto">
    <md-autocomplete #auto="mdAutocomplete">
      <md-option *ngFor="let option of options" [value]="option">
        {{ option }}
      </md-option>
    </md-autocomplete>
  </md-form-field>
</form>

After testing your code snippet using MATERIAL_COMPATIBILITY_MODE, it functioned properly. If you prefer not to use material compatibility mode, consider using snippet C1. For detailed instructions on implementing material compatibility mode for seamless usage of mat- prefix, refer to the link provided: https://github.com/angular/material-prefix-updater#after-running-the-tool

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

Encountering difficulty invoking a component method from d3's call() function

My current setup involves using D3 to drag and drop links in the following manner: .call(d3.drag() .on("start", linkDragStart) .on("drag", linkDragging) .on("end", linkDragEnd)); Recently, I decided to extract this functionality into a separate met ...

Angular app - static List mysteriously clears out upon refresh

My goal is to create a login page using Angular. I have an Angular component with HTML, CSS, and TypeScript files that manage this functionality. The HTML file contains two fields (Username and Password) and two buttons (Login and Register). When a user en ...

Failure during building Angular 13 library with Ivy partial compilation mode

Recently, I encountered an issue while trying to install an npm package that utilized node-gyp. In an attempt to resolve the problem, I upgraded my Node.js minor version from 16.13.0 to 16.13.1 and also updated my Angular CLI from 13.0.2 to 13.2.0. After ...

Error encountered when updating Angular CLI

I am currently attempting to update my Angular project from version 4 to version 6. After numerous failed attempts to upgrade, I decided to uninstall and reinstall the Angular CLI using 'npm uninstall -g angular-cli' followed by a reinstallation. ...

Tests in Angular2 are executed before the variables in compileComponents are initialized

I'm encountering an issue with an Angular2 text component where I receive the following error message when trying to run the testrunner: Component: Product Component Should ensure component subscribes to service EventEmitter on instantiation Failed: ...

Issue found in VS2015 with the sequence of AngularJS TypeScript ts files within the appBundle.js file

I've been diving into AngularJS and TypeScript with the VS2015 RC Cordova TypeScript project. Recently, I created a "MyController.ts" file in the same folder as "index.ts". The code worked perfectly fine: module MyTestApp{ export class MyContro ...

Remove properties that are not part of a specific Class

Is there a way to remove unnecessary properties from the Car class? class Car { wheels: number; model: string; } const obj = {wheels:4, model: 'foo', unwanted1: 'bar', unwantedn: 'kuk'}; const goodCar = filterUnwant ...

Guide on properly setting up and configuring Cypress while using a proxy

After downloading the Cypress zip file and extracting it, I proceeded to run the npm installation command from within the e2e folder of my Angular project: npm install /path_to_cypress_folder/cypress/Cypress/resources/app The installation was successful a ...

PAYEE_ACCOUNT_RESTRICTED: Restrictions have been placed on the merchant account

Currently working on integrating a PayPal payment gateway into an Angular website. Testing with sandbox client ID and secret ID has been successful, but upon switching to live credentials, I encountered the following error: Uncaught Error: PAYEE_ACCOUNT_RE ...

InvalidAction: The function forEach cannot be applied to "res"

Here is the HTML code that I am currently working with: <div *ngIf="chart" class="col-xl-4 col-lg-6"> <div class="card cardColor mb-3"> <div class="card-header headColor"> <img class="img-fluid" src="../../../ ...

Can NODE_PATH be configured in Typescript?

Before, I worked on my React app with ES6 and used NODE_PATH='src' to import files starting from the src folder. However, since switching to Typescript, I've realized that NODE_PATH is not supported. After some investigation, I discovered th ...

Tips on obtaining data from ion-select and presenting it in a label

I'm having a problem with dynamic binding in my drop-down. I can't seem to display the default selected value in the label, and when I change the selection, the new value isn't showing up either. Take a look at my code below: <p>{{l ...

Unable to execute unit tests while utilizing imports that are only for types

Check out this solution I have developed a library that includes both a component and a directive, resulting in an import cycle issue. Component import { Component } from '@angular/core'; @Component({ selector: 'lib-resizable', t ...

ThymeLeaf does not support the parsing of JavaScript code

I'm working on serving an Angular app with spring boot/thymeleaf. This is the structure of my class that sends html/css/javascript: @Controller public class ResourceProvider { @RequestMapping(method = RequestMethod.GET, value = "/") ...

Sharing screen content in Firefox using Angular 6

I am developing an Angular application that requires screen sharing functionality. I am using adapter.js version 6.4.8 and testing it on Firefox Developer 64.0b11 & Firefox 63.0.3. Since browser implementations differ, my main goal is to make the applicati ...

What could be causing my mdx files to not display basic markdown elements such as lists and headings? (Next.js, mdx-bundler)

Trying to implement Kent C Dodds mdx-bundler with the Next.js typescript blog starter example is proving challenging. While it successfully renders JSX and certain markdown elements, basic markdown syntax like lists and paragraph spacing seem to be malfunc ...

Highcharts3d was already defined locally, preventing the import declaration from being recognized with error code TS2440

Struggling to get my application to run in VS code due to this persistent error: error TS2440: Import declaration conflicts with local declaration of 'Highcharts3d' Any assistance in resolving this issue would be greatly appreciated. import ...

When trying to use global.mongoose in Typescript, a type error is being thrown

I'm attempting to incorporate caching into my database connection file in order to streamline the process for my next.js application and avoid repeating the connection step every time I interact with the database. import mongoose from 'mongoose&a ...

Secure higher order React component above class components and stateless functional components

I have been working on creating a higher order component to verify the authentication status of a user. Currently, I am using React 15.5.4 and @types/react 15.0.21, and below is a simplified version of my code: import * as React from 'react'; i ...

Currently, my goal is to create PDFs using Angular

<button class="print" (click)="generatePDF()">Generate PDF</button> Code to Generate PDF generatePDF(): void { const element = document.getElementById('mainPrint') as HTMLElement; const imgWidth = 210; ...