Angular material autocomplete doesn't work, doesn't show any errors


Simeon Nakov

I've implemented autocomplete, no errors, everything works fine, but absolutely nothing happens. I typed something into the input field, but nothing seems to happen, nothing shows up in the console.

HTML

  <form>
    <mat-form-field>
      <input type="text" matInput [formControl]="myControl" [matAutocomplete]="auto">
    </mat-form-field>

    <mat-autocomplete #auto="matAutocomplete">
      <mat-option *ngFor="let n of testValues" [value]="n">
        {{n}}
      </mat-option>
    </mat-autocomplete>
  </form>

TS

import { MatAutocomplete } from '@angular/material/autocomplete';
import { FormControl } from '@angular/forms';
...
public testValues = ['one', 'two', 'three', 'four'];
public myControl: FormControl;
...
constructor() {
    this.myControl = new FormControl();
}

EDIT: I have imported

import {MatAutocompleteModule} from '@angular/material/autocomplete';

in my app module.

Material Version -

"@angular/material": "^5.0.0-rc.2",
Gianluca Paris

you are missing in your filter method.ts

You have to subscribe myControl valueChangesthis way :

this.myControl.valueChanges.subscribe(newValue=>{
    this.filteredValues = this.filterValues(newValue);
})

So every time your form control value changes, you will call your custom filterValues()method which should be something like:

filterValues(search: string) {
    return this.testValues.filter(value=>
    value.toLowerCase().indexOf(search.toLowerCase()) === 0);
}

So you can use testValuesarray as base array and filteredValuesuse array in html:

<mat-option *ngFor="let n of filteredValues" [value]="n">
    {{n}}
</mat-option>

Filtering is not automatic, you must use a custom method to filter options. hope to help you

Related


Ajax doesn't work. it doesn't show any errors

Ati I am using Ajax in my application. Previously it worked fine and checked many times. Not working now. I didn't change anything in this code. I checked the URL path and also checked the Jquery click event. It doesn't show any errors in the console log. $(".

Autocomplete doesn't work, no errors

Dylan Jquery's autocomplete doesn't work for me, but I don't get any errors. I've tested this code on a blank page of my site and it has worked, which leads me to believe the following is conflicting. Javascript: $("#search").autocomplete({ source: function(

Material 2 - Autocomplete doesn't show options

Bavik Patel What I want to achieve md-autocompleteis . The way it is supposed to work is that when the user starts typing, it calls fetch data and displays it in the options. I am able to make the http call, but for some reason it won't work in the .material-2

Material autocomplete doesn't work with InputProps

Arthur I'm trying to change the borders TextFieldrendered through me Autocomplete, but when InputPropsprops are added, s are Autocompleteno longer renderedChip <Autocomplete multiple freeSolo options={options} renderTags={(value, { className, o

Material autocomplete doesn't work with InputProps

Arthur I'm trying to change the borders TextFieldrendered through me Autocomplete, but when InputPropsprops are added, s are Autocompleteno longer renderedChip <Autocomplete multiple freeSolo options={options} renderTags={(value, { className, o

Material autocomplete doesn't work with InputProps

Arthur I'm trying to change the borders TextFieldrendered through me Autocomplete, but when InputPropsprops are added, s are Autocompleteno longer renderedChip <Autocomplete multiple freeSolo options={options} renderTags={(value, { className, o

Material autocomplete doesn't work with InputProps

Arthur I'm trying to change the borders TextFieldrendered through me Autocomplete, but when InputPropsprops are added, s are Autocompleteno longer renderedChip <Autocomplete multiple freeSolo options={options} renderTags={(value, { className, o

Angular material doesn't work in my project and no errors

Naresh Mandeloi Here is my login form, it doesn't render in the browser and there are no elements in the dom. <mat-card> <form [FormGroup]="loginForm"> <mat-form-field> <input type="email" formControlName="email" matInput placeholder="Email

Angular material doesn't work

Yass Ikrou I want to use angular material in my AngularJS application, so I downloaded all its dependencies: <script src="bower_components/hammer/hammer.js"></script> <script src="bower_components/angular/angular.min.js"></script> <script src="bower_components

Angular material doesn't work

Yass Ikrou I want to use angular material in my AngularJS application, so I downloaded all its dependencies: <script src="bower_components/hammer/hammer.js"></script> <script src="bower_components/angular/angular.min.js"></script> <script src="bower_components

Angular material doesn't work

Yass Ikrou I want to use angular material in my AngularJS application, so I downloaded all its dependencies: <script src="bower_components/hammer/hammer.js"></script> <script src="bower_components/angular/angular.min.js"></script> <script src="bower_components

Angular material doesn't work

Yass Ikrou I want to use angular material in my AngularJS application, so I downloaded all its dependencies: <script src="bower_components/hammer/hammer.js"></script> <script src="bower_components/angular/angular.min.js"></script> <script src="bower_components

Angular material table doesn't show any data

Florian My Angular Material table is not showing any data. It also doesn't throw any exceptions, nor any other exceptions. I've read some other stackoverflow posts but couldn't find any useful information. This is what I get when sortedData contains 12 questio

Angular material table doesn't show any data

Florian My Angular Material table is not showing any data. It also doesn't throw any exceptions, nor any other exceptions. I've read some other stackoverflow posts but couldn't find any useful information. This is what I get when sortedData contains 12 questio

Angular material table doesn't show any data

Florian My Angular Material table is not showing any data. It also doesn't throw any exceptions, nor any other exceptions. I've read some other stackoverflow posts but couldn't find any useful information. This is what I get when sortedData contains 12 questio

Angular material table doesn't show any data

Florian My Angular Material table is not showing any data. It also doesn't throw any exceptions, nor any other exceptions. I've read some other stackoverflow posts but couldn't find any useful information. This is what I get when sortedData contains 12 questio

jQuery code doesn't work but also doesn't show any errors

Lionheart Nerd I have some jQuery code that calls into a separate PHP file (which also contains a jQuery countdown clock), and although no errors are displayed, no jQuery code seems to be loaded. The code I use to call the stats_bar.php file is: <?php if(i

jQuery code doesn't work but also doesn't show any errors

Lionheart Nerd I have some jQuery code that calls into a separate PHP file (which also contains a jQuery countdown clock), and although no errors are displayed, no jQuery code seems to be loaded. The code I use to call the stats_bar.php file is: <?php if(i

pygame.font doesn't work and doesn't show any errors

Amar Prakash Pandey Everything works fine except the font, I don't know why this is happening, it doesn't even show any errors. without displaying the text on the screen. # import library here import pygame import time import sys # display init display_width

jQuery code doesn't work but also doesn't show any errors

Lionheart Nerd I have some jQuery code that calls into a separate PHP file (which also contains a jQuery countdown clock) and although no errors are displayed, no jQuery code seems to be loaded. The code I use to call the stats_bar.php file is: <?php if(is

jQuery code doesn't work but also doesn't show any errors

Lionheart Nerd I have some jQuery code that calls into a separate PHP file (which also contains a jQuery countdown clock), and although no errors are displayed, no jQuery code seems to be loaded. The code I use to call the stats_bar.php file is: <?php if(i

Python asyncio doesn't show any errors

superman I am trying to get some data from thousands of URLs by using asyncio. Here is a brief overview of the design: QueuePopulate a bunch of URLs at once with one URLProducer generate a bunchConsumers Each Consumerkeeps fetching urls from Queueand sending G

Python asyncio doesn't show any errors

superman I am trying to get some data from thousands of URLs by using asyncio. Here is a brief overview of the design: QueuePopulate a bunch of URLs at once with one URLProducer generate a bunchConsumers Each Consumerkeeps fetching urls from Queueand sending G

PHP doesn't show any errors

UserIsCorrupt I know this question has been asked many times in the past, but none of the solutions worked for me. Here is my PHP code: <?php function ?> This should generate an error. However, it just returns a 500 error and doesn't load. I tried the less

Python asyncio doesn't show any errors

superman I am trying to get some data from thousands of URLs by using asyncio. Here is a brief overview of the design: QueuePopulate a bunch of URLs at once with one URLProducer generate a bunchConsumers Each Consumerkeeps fetching urls from Queueand sending G