0

I'm currently running a new project using Angular and Material

EDIT : Here is a stackblitz : https://stackblitz.com/edit/angular-ivy-tzxfxr?file=src/app/app.component.html

I'm trying to makes the example of the toolbar, but here is the results :

https://i.sstatic.net/MUVWb.png

I try to put the example code into the app.component.html :

<mat-toolbar>
  <button mat-icon-button class="example-icon" aria-label="Example icon-button with menu icon">
    <mat-icon>menu</mat-icon>
  </button>
  <span>My App</span>
  <span class="example-spacer"></span>
  <button mat-icon-button class="example-icon favorite-icon" aria-label="Example icon-button with heart icon">
    <mat-icon>favorite</mat-icon>
  </button>
  <button mat-icon-button class="example-icon" aria-label="Example icon-button with share icon">
    <mat-icon>share</mat-icon>
  </button>
</mat-toolbar>


<router-outlet></router-outlet>

And the app.component.ts :

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

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})

export class AppComponent {
  title = 'OpenCaptureForInvoices';
}

To import the Material module I have a app-material.module.ts file

import { MatToolbarModule } from '@angular/material/toolbar';
@NgModule({
    imports: [
        MatToolbarModule,
        MatButtonModule,
        MatIconModule
    ],
    exports: [
        MatToolbarModule,
        MatButtonModule,
        MatIconModule
    ]
})
export class AppMaterialModule { }

This last file is included into the app.module.ts

Did I do something wrong ?

2
  • 1
    Can you set up a stackblitz? Otherwise it is hard to reproduce the error... Commented Dec 11, 2020 at 15:54
  • I edit the post :) Commented Dec 11, 2020 at 16:03

1 Answer 1

2

The problem is that the icons are not loading. This is because you didn't include the Material icon font to your project.

Add this to your index.html:

<link href="https://fonts.googleapis.com/icon?family=Material+Icons"
      rel="stylesheet">

See also the Angular Material documentation how to setup the project properly.

Sign up to request clarification or add additional context in comments.

2 Comments

No problem, glad I could help you :)
@JSON ,I have one question in regards to the angular material table can you please help here. stackoverflow.com/questions/65347251/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.