首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Angular 8 mat-autocomplete错误- 'matAutocomplete‘,因为它不是'input’的已知属性

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

Stack Overflow用户
提问于 2020-05-18 18:02:51
回答 1查看 755关注 0票数 0

我正在尝试使用来自materialUI的示例here来处理Angular 8,mat-chip-list在没有mat-autocomplete的情况下工作得很好,但我需要它。这是我的代码:

代码语言:javascript
复制
        <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>

我得到了这个错误:

代码语言:javascript
复制
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)

我不明白为什么我会得到这个错误:(

EN

回答 1

Stack Overflow用户

发布于 2020-05-18 18:36:52

问题修复:

代码语言:javascript
复制
1) open app.module.ts 
2) import MatAutocompleteModule from @angular/material
3) add MatAutocompleteModule to the NgModule imports

为我修复了这个问题!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61867076

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档