- Tool bar displays information and actions related to the current screen.
- It is used for branding screen titles, navigation and actions.
- In the below example we will see how we can use tool bar as a nav bar.
material.module.ts
import { NgModule } from '@angular/core'; import { MatButtonModule } from '@angular/material'; import { MatProgressSpinnerModule} from '@angular/material/progress-spinner'; import { MatBadgeModule } from '@angular/material/badge'; import { MatButtonToggleModule} from '@angular/material/button-toggle'; import { MatIconModule} from '@angular/material/icon'; import { MatToolbarModule} from '@angular/material/toolbar'; const MaterialComponent = [ MatButtonModule, MatButtonToggleModule, MatIconModule, MatBadgeModule, MatProgressSpinnerModule, MatToolbarModule ]; @NgModule({ imports: [ MaterialComponent, ], exports: [ MaterialComponent ] }) export class MaterialModule { }
app.module.ts
import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; import { AppComponent } from './app.component'; import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; import { MaterialModule } from './material/material.module'; @NgModule({ declarations: [ AppComponent ], imports: [ BrowserModule, BrowserAnimationsModule, MaterialModule ], providers: [], bootstrap: [AppComponent] }) export class AppModule { }
app.component.html
<mat-toolbar color="primary" class="navbar"> <div>HeapWizard.com</div> <div> <span>Home</span> <span>About</span> <span>Services</span> </div> </mat-toolbar>
app.component.css
.navbar{ justify-content: space-between; } span{ padding-right: 1rem; }