我正在尝试使用示例 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/