Is there a way to use a mat-autocomplete where the corresponding input is in its parent component?


This works with a regular datalist element where the list="target" on the input element can find the id="target" in the child component. I am trying to figure out a way to do this with the material autocomplete component.

Using a regular datalist element


 <input type="text" list="target">


<datalist id="target">
    <option *ngFor="let option of options" [value]=""></option>

I have been trying to implement this feature all day I usually get one of two errors:

Error: Attempting to open an undefined instance of `mat-autocomplete`. Make sure that the id passed to the `matAutocomplete` is correct and that you're attempting to open it after the ngAfterContentInit hook.


Error: Export of name 'matAutocomplete' not found!

Using a Mat-Form-Field and a Mat-Autocomplete


    <input type="text" matInput [matAutocomplete]="auto">


<mat-autocomplete #auto="matAutocomplete">
    <mat-option *ngFor="let option of options" [value]=""</option>


I landed here because I was looking for the “Error: Export of name ‘matAutocomplete’ not found!” string. I fixed it in my project by importing the MatAutocompleteModule.
So in the module.ts of your component you’ll want to add the following:

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

(then scroll down to your imports array)

imports: [

Concerning the main question, I’m kind of new to Angular myself but afaik if you want to pass your text from the parent to the children you’ll need to use an ‘Input’.

I’d recommend you to read the corresponding part of the documentation, I can’t explain it any better than that:

I hope it helps 🙂

Answered By – PLB

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published