mat-tab-group在Angular 5项目中不起作用,我已经按照他们的文档中的说明安装了所有必需的依赖项,我知道Angular 4已经存在与此类似的问题,即说要安装BrowserAnimationsModule,但是我尝试过仍然无法正常工作,
模板:
<div class="try">
<mat-tab-group>
<mat-tab label="First"> Content 1 </mat-tab>
<mat-tab label="Second"> Content 2 </mat-tab>
<mat-tab label="Third"> Content 3 </mat-tab>
</mat-tab-group>
</div>
appModule.ts文件:
imports: [
BrowserModule,
NgxPaginationModule,
HttpModule,
TabModule,
FormsModule,
NgxPopper ,
MDBBootstrapModule.forRoot(),
RouterModule.forRoot(
appRoutes,
{ enableTracing: true } // <-- debugging purposes only
),
BrowserAnimationsModule,
MatTabsModule,
MatTableModule,
答案 0 :(得分:1)
HTML:
<mat-tab-group >
<mat-tab label="Short tab">
<div class="example-small-box mat-elevation-z4">
Small content
</div>
</mat-tab>
<mat-tab label="Long tab">
<div class="example-large-box mat-elevation-z4">
Large content
</div>
</mat-tab>
</mat-tab-group>
app.module.ts
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { MatLabel } from '@angular/material';
import {MatTabsModule} from '@angular/material/tabs';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { AppComponent } from './app.component';
import { HelloComponent } from './hello.component';
@NgModule({
imports: [ BrowserModule, FormsModule,BrowserAnimationsModule,MatTabsModule ],
declarations: [ AppComponent, HelloComponent ],
bootstrap: [ AppComponent ]
})
export class AppModule { }
style.css:
@import "~@angular/material/prebuilt-themes/indigo-pink.css";
答案 1 :(得分:0)
您需要将其添加到组件所在的模块中
import { MatTabsModule } from '@angular/material';
@NgModule({
imports: [
...
MatTabsModule,
...
]
})
导出类SomeModule {}