angular - 没有将 exportAs 设置为 matAutocomplete 的指令

标签 angular typescript angular-material angular-material2

错误

There is no directive with "exportAs" set to "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 组件

<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--版本

@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

谁能提出为什么 angular 会提示。

最佳答案

要使用 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

关于angular - 没有将 exportAs 设置为 matAutocomplete 的指令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48579882/

相关文章:

Angular2 拖放目标

javascript - Angularjs $anchorScroll.yOffset 不适用于 ng-sticky header

javascript - Angular 的 $mdDialog 中使用了什么范围

css - Angular Material md-list flexing

html - Angular 自定义指令 css 折叠子菜单

javascript - Angular karma Jasmine 错误 : Illegal state: Could not load the summary for directive

angular - 条件运算符不适用于 ngStyle

typescript - 是否可以避免此通用函数体中的类型断言?

Angular 4 : "Http failure response for (unknown URL): 0 Unknown Error"

TypeScript:使用数组获取深度嵌套的属性值