Hello, in this tutorial, I will be talking about the Button Component from Angular Material.
Hello, in this tutorial, I will be talking about the Button Component from Angular Material.
To begin, add the MatButtonModule to your project. Go to the app module typescript file, add the import statement and add it to the app.
Go to a html page and add a button element.
<button>Default Button</button>
If you want to use the basic type button, add the mat-button attribute to the button. This will apply the styles and effects for the basic button.
<button mat-button>Default Button</button>
<button mat-button>Default Button</button>
To change the default color of the buttons, apply the color attribute and set it to either primary, accent, or warn. This will allow us to set the buttons with the predefined color based on our theme.
<button mat-button color="primary">Default Button</button>
We can also use our own styles if we choose to.
<button mat-button
For the icon button, we use mat-icon-button.
<button mat-icon-button></button>
Then in between the button element tags, we put an icon.
https://material.io/resources/icons/
To begin using the icons from the library, add the MatIconModule to the project. Go back to the app module typescript file, add the import, and then add it to the app.
Go back to the buttons and add a mat-icon element inside the button.
<button mat-icon-button>
Then choose an icon from the material design icon website and place the icon name inside the mat-icon element.
<button mat-icon-button>
For the fab button, use the mat-fab, and for mini fabs, use mat-mini-fab.
<button mat-fab>
Lastly, as best practice for accessibility, we should give our icon buttons a label using the aria-label or aria-labelledby attribute.
<button mat-fab aria-label="iconButton">