I am creating Navigation drawer in my angular 4 app using angular-material. Initially, I am creating a toolbar to have header and menu button(mat-icon is menu)
Here is my code,
<mat-toolbar class="example-header" color="primary">
<button mat-icon-button><mat-icon>menu</mat-icon></button>
<span class="header-name">Hello</span>
</mat-toolbar>
But I am getting the output as follows,
But I wanted output something like this,
The difference in the output is, the mat-icon button has grey background whereas the required doesn't. Please correct me.
The app.module.ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AgmCoreModule } from '@agm/core';
import { MapsAPILoader } from '@agm/core';
import { FormsModule } from '@angular/forms';
import { GoogleMapsAPIWrapper } from '@agm/core';
import { AppComponent } from './app.component';
import 'hammerjs';
import {
MatAutocompleteModule,
MatButtonModule,
MatButtonToggleModule,
MatCardModule,
MatCheckboxModule,
MatChipsModule,
MatDatepickerModule,
MatDialogModule,
MatExpansionModule,
MatFormFieldModule,
MatGridListModule,
MatIconModule,
MatInputModule,
MatListModule,
MatMenuModule,
MatNativeDateModule,
MatPaginatorModule,
MatProgressBarModule,
MatProgressSpinnerModule,
MatRadioModule,
MatRippleModule,
MatSelectModule,
MatSidenavModule,
MatDrawer, MatDrawerContainer, MatDrawerContent,
MatSliderModule,
MatSlideToggleModule,
MatSnackBarModule,
MatSortModule,
MatTableModule,
MatTabsModule,
MatToolbarModule,
MatTooltipModule,
MatStepperModule,
MATERIAL_SANITY_CHECKS
} from '@angular/material';
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
FormsModule,
BrowserAnimationsModule,
MatToolbarModule,
MatSidenavModule,
MatIconModule
],
providers: [GoogleMapsAPIWrapper],
bootstrap: [AppComponent]
})
export class AppModule { }
Since Angular Material uses 'Material Icons' Font-Family, the icon size depends on font-size. Therefore, if you want to modify the size of the icon then you change its font-size in your CSS file. You have to set the width and height too.
mat-icon makes it easier to use vector-based icons in your app. This directive supports both icon fonts and SVG icons, but not bitmap-based formats (png, jpg, etc.).
If you have overwritten some existing Angular Material styling or any other styling that somehow affects the icon, it may cause an issue. Move the icon code outside of any styling and test. So I just moved it to the child element. Below is part of Angular Material grid.
We have to import MatIconModule from Angular Material Modules. These icons are not limited to angular,In HTML webpages just use <i></i> in place of <mat-icon> tag.
<mat-icon> is part of angular material module called MatIconModule .We can use font ligature as an icon by putting the ligature text in <mat-icon> component. For example <mat-icon>home</mat-icon> displays home icon. We have to import MatIconModule from Angular Material Modules.
We have to import MatIconModule from Angular Material Modules. These icons are not limited to angular,In HTML webpages just use <i></i> in place of <mat-icon> tag. All the material icons packaged into a single font file. All we need to do is adding the below Google web fonts css in our html page.
In your app.module.ts
, you forgot to import MatButtonModule
into your module. (By the way, you shouldn't import every single module if you don't even use it. It's a bad idea!)
@NgModule({
imports: [
MatButtonModule
// ...
]
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With