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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With