我无法理解我的代码出了什么问题,我导入了模块,但仍然收到此错误“未找到名称导出'matAutocomplete'”
注意:我在导入 MatAutocompleteModule 后重新启动了几次编译的 IDE,还是一样。
这是 app.module.ts - 仅粘贴代码的相关部分
import {MatAutocompleteModule} from '@angular/material/autocomplete';
@NgModule({ declarations:[..xxxx....],
imports:[xx,xxx,MatAutocompleteModule],
providers:[xx,xx],
bootstrap: [AppComponent]})
export class AppModule { }
组件.html
<form class="form-group-parent p-0" [formGroup]="frmStep1" (ngSubmit)="submit()">
<mat-form-field class="example-full-width">
<input type="text" placeholder="Ex. English" aria-label="Language" matInput
[formControl]="language" [matAutocomplete]="auto">
<mat-autocomplete autoActiveFirstOption #auto="matAutocomplete">
<mat-option *ngFor="let option of languageList | async" [value]="option">
{{option}}
</mat-option>
</mat-autocomplete>
<mat-error>
<strong>Language</strong> is required.
</mat-error>
</mat-form-field>
</form>
组件.ts
import {Component, OnInit} from '@angular/core';
import {FormControl, FormBuilder, FormGroup, Validators } from '@angular/forms';
import {Observable} from 'rxjs';
import {map, startWith} from 'rxjs/operators';
@Component({
selector: 'xxxx',
templateUrl: './cxx.component.html',
styleUrls: ['./xxx.component.scss']
})
export class xxxComponent implements OnInit {
constructor(
private pageTitle: Title,
private router: Router,
private fb: FormBuilder,
private http: HttpClient,
) { this.createForm(); }
frm1:FormGroup;
frm2:FormGroup;
languageList: Array<any> = ['A','B','C','D','E']
filteredOptions: Observable<string[]>;
ngOnInit():void{
this.filteredOptions = this.frmStep2.valueChanges.pipe(
startWith(''),
map(value => this._filter(value))
);
}
createForm(): object {
this.frmStep1 = this.fb.group({
language:[,[Validators.required]]
});
return frmStep1 :this.frmStep1
}
}