mat-sidenav-content抛出MatSidenavContainer没有提供程序

时间:2019-10-23 12:40:53

标签: angular angular-material

app.component.html

<mat-side-nav-container>

    <mat-sidenav #sidenav>
        <mat-nav-list>
            <a mat-list-item [routerLink]="'/accounts'"> Accounts </a>
            <a mat-list-item [routerLink]="'/create-account'"> Create Account </a>
            <a mat-list-item [routerLink]="'/contacts'"> Contacts </a>
            <a mat-list-item [routerLink]="'/create-contact'"> Create Contact </a>
            <a mat-list-item [routerLink]="'/activities'"> Activities </a>
            <a mat-list-item [routerLink]="'/create-activity'"> Create Activity </a>
            <a mat-list-item (click)="sidenav.toggle()" href="" mat-list-item>Close</a>
        </mat-nav-list>
    </mat-sidenav>
    <mat-sidenav-content></mat-sidenav-content>
</mat-side-nav-container>

app.moule.ts

@NgModule({
  declarations: [
    AppComponent,
  ],
  imports: [
    BrowserModule,
    BrowserAnimationsModule,    
    MatToolbarModule,
    MatSidenavModule,
    MatListModule,
    MatButtonModule,
    MatIconModule,
    HttpClientModule,
    AppRoutingModule,
  ],
  providers: [],
  bootstrap: [AppComponent],
  schemas: [CUSTOM_ELEMENTS_SCHEMA]
})
export class AppModule { }

MatSidenavModulemodule 已导入,但仍然出现以下错误

  

NullInjectorError:StaticInjectorError(AppModule)[MatSidenavContent->   MatSidenavContainer]:StaticInjectorError(Platform:   核心)[MatSidenavContent-> MatSidenavContainer]:       NullInjectorError:MatSidenavContainer没有提供程序!

1 个答案:

答案 0 :(得分:0)

您在代码中输入了错误:

  

mat-sidenav-容器

您有:

  

mat-side-nav-容器

将mat-side-nav-container替换为mat-sidenav-container。