How to use <mat-chip-list> and <mat-chip> in Angular Material ?

08 Feb, 2021
Angular Material is a UI component library that is developed by the Angular team to build design components for desktop and mobile web applications. In order to install it, we need to have angular installed in our project, once you have it you can enter the below command and can download it. mat-chip-list is used mainly for labels.
Installation syntax:
ng add @angular/material
Approach:
First, install the angular material using the above-mentioned command.
After completing the installation, Import ‘MatChipsModule’ from ‘@angular/material/chips’ in the app.module.ts file.
Then use the <mat-chip-list> tag to group all the labels or items inside this group tag.
Inside the <mat-chip-list> tag we need to use <mat-chip> tag for every item or labels.
In Angular material, we also have a chip-list type called stack chip-list where all the chips or labels are displayed vertically like a stack.
In order to display in such a form, we need to use this class name “mat-chip-list-stacked”.
If we want to change the theme then we can change it by using the color property. In angular we have 3 themes, they are primary, accent, and warn.
Once done with the above steps then serve or start the project.
Project Structure: It will look like the following.
Code Implementation:
app.module.ts:
Javascript
import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { FormsModule } from '@angular/forms'; import { MatChipsModule } from '@angular/material/chips';       import { AppComponent } from './app.component'; import { BrowserAnimationsModule } from '@angular/platform-browser/animations';    @NgModule({   imports:   [ BrowserModule,     FormsModule,     MatChipsModule,    BrowserAnimationsModule],   declarations: [ AppComponent ],   bootstrap: [ AppComponent ] }) export class AppModule { }
app.component.html:
HTML
<p>Default Chip List</p>  <mat-chip-list aria-label="Fish selection">    <mat-chip color="primary" selected>        Primary theme chip    </mat-chip>          <mat-chip color="accent" selected>        Accent theme chip     </mat-chip>          <mat-chip color="warn" selected>        Warn theme chip    </mat-chip>          <mat-chip>Default theme chip </mat-chip></mat-chip-list><br><br><br>  <p>Stacked Chip List</p>  <mat-chip-list class="mat-chip-list-stacked"    aria-label="Fish selection">          <mat-chip color="primary" selected>        Primary theme chip     </mat-chip>          <mat-chip color="accent" selected>        Accent theme chip    </mat-chip>          <mat-chip color="warn" selected>        Warn theme chip    </mat-chip>          <mat-chip>Default theme chip </mat-chip></mat-chip-list>
Output:
Angular-material
Picked
AngularJS
Web Technologies
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Routing in Angular 9/10
Angular PrimeNG Dropdown Component
Angular 10 (blur) Event
How to make a Bootstrap Modal Popup in Angular 9/8 ?
How to setup 404 page in angular routing ?
Installation of Node.js on Linux
Top 10 Projects For Beginners To Practice HTML and CSS Skills
Difference between var, let and const keywords in JavaScript
How to insert spaces/tabs in text using HTML/CSS?
How to fetch data from an API in ReactJS ?