首页 文章

exportAs设置为matAutocomplete时没有指令

提问于
浏览
1

Error

没有指令将“exportAs”设置为“matAutocomplete”(“ - label =”Number“matInput [formControl] =”myControl“[matAutocomplete] =”auto“>

我使用了https://material.angular.io/components/autocomplete/overview的代码

我还在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

任何人都可以建议为什么角度抱怨 .

1 回答

  • 1

    要使用 mat-form-field ,您必须将 @angular/material@angular/cdk 版本更新为至少2.0.0-beta.12 . 使用以下命令进行更新:

    npm install @angular/cdk@2.0.0-beta.12
    npm install @angular/material@2.0.0-beta.12
    

    然后,您在 AppModule 中导入以下内容:

    import { MatAutocompleteModule, MatFormFieldModule } from '@angular/material';
    
    @NgModule({
        imports: [
            ....
            MatAutocompleteModule, 
            MatFormFieldModule,
            ....
        ],
        ....
    })
    export class AppModule { }
    

    这是一个工作StackBlitz demo使用版本 2.0.0-beta.12

相关问题