Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

There is no directive with exportAs set to matAutocomplete

Error

There is no directive with "exportAs" set to "matAutocomplete" ("-label="Number" matInput [formControl]="myControl" [matAutocomplete]="auto">

I have used code from https://material.angular.io/components/autocomplete/overview

I have also include in import in angular app.module.ts:

import { 
         MdAutocompleteModule,

  } from '@angular/material';

Html component

<form class="example-form">
    <mat-form-field class="example-full-width">
        <input type="text" placeholder="Pick one" aria-label="Number" 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>

ng--version

@angular/cli: 1.2.1
node: 8.3.0
os: win32 x64
@angular/animation: 4.0.0-beta.8
@angular/animations: 4.3.3
@angular/cdk: 2.0.0-beta.8
@angular/common: 4.3.2
@angular/compiler: 4.3.2
@angular/core: 4.3.6
@angular/forms: 4.3.2
@angular/http: 4.3.2
@angular/material: 2.0.0-beta.8
@angular/platform-browser: 4.3.2
@angular/platform-browser-dynamic: 4.3.2
@angular/router: 4.3.2
@angular/cli: 1.2.1
@angular/compiler-cli: 4.4.3
@angular/language-service: 4.3.2

can anyone suggest why angular is complaining about.

like image 478
afeef Avatar asked Feb 02 '18 09:02

afeef


Video Answer


1 Answers

To use mat-form-field, you have to update your @angular/material and @angular/cdk versions to atleast 2.0.0-beta.12. Use the following commands to update:

npm install @angular/[email protected]
npm install @angular/[email protected]

Then, you have import the following in your AppModule:

import { MatAutocompleteModule, MatFormFieldModule } from '@angular/material';

@NgModule({
    imports: [
        ....
        MatAutocompleteModule, 
        MatFormFieldModule,
        ....
    ],
    ....
})
export class AppModule { }

Here is a working StackBlitz demo using version 2.0.0-beta.12

like image 71
Faisal Avatar answered Oct 05 '22 22:10

Faisal