整个错误是这样的:NullInjectorError: R3InjectorError(AppModule)[MatSelectionList -> MatSelectionList -> MatSelectionList]: NullInjectorError: No provider for MatSelectionList!
我真的不明白发生了什么,我在另一个组件中有这个元素并且它可以正常工作,我肯定会导入它,这是我的模块:
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { SidenavComponent } from './sidenav.component';
import { MatToolbarModule } from '@angular/material/toolbar';
import { SidenavItemModule } from './sidenav-item/sidenav-item.module';
import { ScrollbarModule } from '../../components/scrollbar/scrollbar.module';
import { FlexLayoutModule } from '@angular/flex-layout';
import { MatButtonModule } from '@angular/material/button';
import { MatIconModule } from '@angular/material/icon';
import { IconModule } from '@visurel/iconify-angular';
import {MatListModule} from '@angular/material/list';
import {MatDividerModule} from '@angular/material/divider';
import { AlertModule } from 'ngx-alerts';
import { MatTooltipModule } from '@angular/material/tooltip';
import {MatGridListModule} from '@angular/material/grid-list';
import { MatSelectModule } from '@angular/material/select';
@NgModule({
declarations: [SidenavComponent],
imports: [
AlertModule.forRoot({maxMessages: 4, timeout: 3000, position: 'right'}),
CommonModule,
MatToolbarModule,
SidenavItemModule,
ScrollbarModule,
FlexLayoutModule,
MatButtonModule,
MatIconModule,
IconModule,
MatDividerModule,
MatTooltipModule,
MatGridListModule,
MatSelectModule,
MatListModule
],
exports: [SidenavComponent]
})
export class SidenavModule {
}
编辑:
我是个笨蛋,问题不在模块上,它实际上在 HTML 上,我没有使用它的 mat-selection-list 部分,只是列出了 mat-list-option。
<mat-selection-list #shoes [multiple]="false">
<mat-list-option *ngFor="let shoe of typesOfShoes" [value]="shoe">
{{shoe}}
</mat-list-option>
</mat-selection-list>
倚天杖
相关分类