html - Angular 8 mat-autocomplete 错误 - 'matAutocomplete',因为它不是 'input' 的已知属性

标签 html angular typescript angular-material

我正在尝试使用示例 here来自 Material 用户界面 使用 Angular 8 mat-chip-list 在没有 mat-autocomplete 的情况下工作正常,但我需要它。 这是我的代码:

        <mat-chip-list #chipList aria-label="Content selection">
          <mat-chip *ngFor="let item of content" [selectable]="selectable"
                   [removable]="removable" (removed)="remove(item)">
            {{item}}
            <mat-icon matChipRemove *ngIf="removable">cancel</mat-icon>
          </mat-chip>
          <input matInput 
                 #contentInput
                 [formControl]="contentCtrl" 
                 [matAutocomplete]="auto"
                 [matChipInputFor]="chipList"
                 [matChipInputSeparatorKeyCodes]="separatorKeysCodes"
                 [matChipInputAddOnBlur]="addOnBlur"
                 (matChipInputTokenEnd)="add($event)">
        </mat-chip-list>
        <mat-autocomplete #auto="matAutocomplete" (optionSelected)="selected($event)">
          <mat-option *ngFor="let item of filteredContent | async" [value]="item">
            {{item}}
          </mat-option>
        </mat-autocomplete>
      </mat-form-field>

我收到此错误:

Can't bind to 'matAutocomplete' since it isn't a known property of 'input'. ("
        #contentInput
        [formControl]="contentCtrl" 
        [ERROR ->][matAutocomplete]="auto"
        [matChipInputFor]="chipList"
        [matChipInputSeparatorKeyCode"): ng:///AppModule/InviteMemberComponent.html@60:8
    at syntaxError (compiler.js:2175)
    at TemplateParser.parse (compiler.js:11388)
    at JitCompiler._parseTemplate (compiler.js:25963)
    at JitCompiler._compileTemplate (compiler.js:25951)
    at compiler.js:25895
    at Set.forEach (<anonymous>)
    at JitCompiler._compileComponents (compiler.js:25895)
    at compiler.js:25808
    at Object.then (compiler.js:2166)
    at JitCompiler._compileModuleAndComponents (compiler.js:25807)

我不明白为什么会收到此错误:(

最佳答案

问题修复:

1) open app.module.ts 
2) import MatAutocompleteModule from @angular/material
3) add MatAutocompleteModule to the NgModule imports

帮我解决了这个问题!

关于html - Angular 8 mat-autocomplete 错误 - 'matAutocomplete',因为它不是 'input' 的已知属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61867076/

相关文章:

html - 如何在我的应用程序中离线使用下载的 Google 字体?

html - 具有响应式中央列的 3 列布局

angular - 使用 Angular HTTP Observable 的轮询 API

angular - Kendo Grid for Angular 2 Reactive FormArray

javascript - 保存复选框

javascript - 需要帮助修复 Javascript Accordion 最小化和最大化问题(检查附加的 JsFiddle 和步骤)

javascript - angular overlay cdk global positioning strategy和drop element in anywhere in grey area相关的问题

javascript - 在 typescript 类中使用 "this"

angular - 空合并运算符 Angular 2

javascript - ECMAScript 6 在对象解构中扩展了语法。支持 TypeScript 和 Babel