角材料在角版本9中不起作用

问题描述 投票:-2回答:1

我将角度版本8更新为角度9,还将角度材料更新为版本9,但它不起作用且未显示任何错误。如何解决。

这里是代码材料模块

import { NgModule } from '@angular/core';
import {MatButtonModule} from '@angular/material/button';

 @NgModule({
  declarations: [],
  imports: [
    MatButtonModule
  ] 
})
export class MaterialModule { }

app-component.html

<h3>Stroked Buttons</h3>
 <div class="example-button-row">
  <button mat-stroked-button>Basic</button>
  <button mat-stroked-button color="primary">Primary</button>
  <button mat-stroked-button color="accent">Accent</button>
  <button mat-stroked-button color="warn">Warn</button>
  <button mat-stroked-button disabled>Disabled</button>
  <a mat-stroked-button routerLink=".">Link</a>
 </div>

app.module

 import { BrowserModule } from '@angular/platform-browser';
 import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
 import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { BrowserAnimationsModule } from '@angular/platform browser/animations';
 import { MaterialModule } from './angular-material/material/material.module';
  import { MatButtonModule } from '@angular/material/button';



@NgModule({
 declarations: [
  AppComponent
 ],
 imports: [
   BrowserModule,
   AppRoutingModule,
   BrowserAnimationsModule,
    MaterialModule,    
  ],
  providers: [],
  bootstrap: [AppComponent],
  schemas: [ CUSTOM_ELEMENTS_SCHEMA ]
 })
 export class AppModule { }
angular angular-material angular-material2 angular9
1个回答
0
投票

您可能还需要向出口添加任何物料模块,如下所示:

import { NgModule } from '@angular/core'; 

import {MatButtonModule} from '@angular/material/button';

@NgModule({
   declarations: [],
   imports: [ MatButtonModule ],
   exports: [ MatButtonModule ]
})

export class MaterialModule { }

这是我在项目中使用的material.module的示例:

import { NgModule } from '@angular/core';

import { MatButtonModule } from '@angular/material/button';
import { MatIconModule } from '@angular/material/icon';
import { MatMenuModule } from '@angular/material/menu';
import { MatSidenavModule } from '@angular/material/sidenav';
import { MatSlideToggleModule } from '@angular/material/slide-toggle';
import { MatToolbarModule } from '@angular/material/toolbar';

const mat = [
  MatButtonModule,
  MatIconModule,
  MatMenuModule,
  MatSidenavModule,
  MatSlideToggleModule,
  MatToolbarModule,
];

@NgModule({
  imports: [
    ...mat,
  ],
  exports: [
    ...mat,
  ],
})
export class MaterialModule { }

这样,添加到阵列的所有内容都将导入并导出到其他模块。

© www.soinside.com 2019 - 2024. All rights reserved.