Angular Material chips tutorials | Best five mat-chip-list examples


Angular material chips are used to display group of tags in single element as a chips for a blog posts.

These can be used in the following cases Input chips used to represent type of entered information filter chips used to filter the group of data, example is an category or tags of an blog post content

Basic Chip UI component contains followings

  • Chip container - It is an required parent container for holding group of elements or chips
  • image - It is an optional thumbnail image of an Chips to display the type of chips
  • string - Name of the chip, examples are tags,
  • delete icon - Optional close icon to close the chip.

In this blog post, List out the various examples of usage of chips using angular material.

This posts does’nt cover how to create an angular applicaiton, And it covers adding chips code to angula application

Angular material chips

Chip is an UI element to display list of objects in individual elements in the form chips. matChip is an selector used to display the material style of chips in UI pages.

Chips related components are inbuilt in angular module in the form of ‘MatChipsModule’.

Import angular material chip module

All you need to is import MatChipsModule module in your application. You can add import in your component, app.module.ts or shared common module. I am adding this module to app.module.ts file.

app.module.ts
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
import { NgModule } from '@angular/core';
import { MatChipsModule } from '@angular/material/chips';

@NgModule({
  imports:      [ MatChipsModule],
  declarations: [ AppComponent],
  bootstrap:    [ AppComponent ],
  providers:[],
  exports:[]
})
export class AppModule { }

Now application has access to following components and directives of MatChipsModule available in your components.

  • mat-chip-list,matChipRemove selectors etc…
  • mat-chip-list and mat-chip components
  • matChipList directives

What is next step?

material chips basic example

We are going to create a basic chip lists elements in angular using mat-chip-list component.

In my system, I already installed choco command, Please issue choco command in command console to check installed or information

C:\Users>choco
Chocolatey v0.10.15
Please run 'choco -?' or 'choco <command> -?' for help menu.

Chocolatey already installed with a v0.10.15  version.

So now good to go with setup Haskell platform on a windows machine

Next run install haskell-dev using choco

I tried to run in command prompt with below command, But  got the message ‘Chocolatey detected you are not running from an elevated command shell’,

We need to run command choco install haskell-dev  from Powershell.

Here is the output,

C:\Users>choco install haskell-dev
Chocolatey v0.10.15
Chocolatey detected you are not running from an elevated command shell
 (cmd/powershell).

 You may experience errors - many functions/packages
 require admin rights. Only advanced users should run choco w/out an
 elevated shell. When you open the command shell, you should ensure
 that you do so with "Run as Administrator" selected. If you are
 attempting to use Chocolatey in a non-administrator setting, you
 must select a different location other than the default install
 location. See
 https://chocolatey.org/install#non-administrative-install for details.


 Do you want to continue?([Y]es/[N]o): No

type Windows Powershell in windows search box

Open shell with administration role as follows

Haskell platform install in windows
PS C:\WINDOWS\system32> choco install haskell-dev
Chocolatey v0.10.15
Installing the following packages:
Haskell-dev
By installing you accept licenses for the packages.

cabal v3.2.0.0 [Approved]
cabal package files install completed. Performing other installation steps.
The package cabal wants to run 'chocolateyInstall.ps1'.
Note: If you don't run this script, the installation will fail.
Note: To confirm automatically next time, use '-y' or consider:
choco feature enable -n allowGlobalConfirmation
Do you want to run the script?([Y]es/[A]ll - yes to all/[N]o/[P]rint): Y

Downloading cabal 64 bit
  from 'https://downloads.haskell.org/cabal/cabal-install-3.2.0.0/cabal-install-3.2.0.0-x86_64-unknown-mingw32.zip'
Progress: 100% - Completed download of C:\Users\Kiran\AppData\Local\Temp\chocolatey\cabal\3.2.0.0\cabal-install-3.2.0.0-x86_64-unknown-mingw32.zip (5.15 MB).
Download of cabal-install-3.2.0.0-x86_64-unknown-mingw32.zip (5.15 MB) completed.
Hashes match.
Extracting C:\Users\Kiran\AppData\Local\Temp\chocolatey\cabal\3.2.0.0\cabal-install-3.2.0.0-x86_64-unknown-mingw32.zip to C:\ProgramData\chocolatey\lib\cabal\tools\cabal-3.2.0.0...
C:\ProgramData\chocolatey\lib\cabal\tools\cabal-3.2.0.0
Could not read cabal configuration key 'install-method'.
Updated cabal configuration.
PATH environment variable does not have C:\Users\Kiran\AppData\Roaming\cabal\bin in it. Adding...
Adding C:\ProgramData\chocolatey\bin\mingw64-pkg.bat and pointing it to powershell command C:\ProgramData\chocolatey\lib\cabal\tools\mingw64-pkg.ps1
Environment Vars (like PATH) have changed. Close/reopen your shell to
 see the changes (or in powershell/cmd.exe just type `refreshenv`).
 ShimGen has successfully created a shim for cabal.exe
 The install of cabal was successful.
  Software installed to 'C:\ProgramData\chocolatey\lib\cabal\tools\cabal-3.2.0.0'

ghc v8.10.1 [Approved]
ghc package files install completed. Performing other installation steps.
The package ghc wants to run 'chocolateyInstall.ps1'.
Note: If you don't run this script, the installation will fail.
Note: To confirm automatically next time, use '-y' or consider:
choco feature enable -n allowGlobalConfirmation
Do you want to run the script?([Y]es/[A]ll - yes to all/[N]o/[P]rint): Y

Downloading ghc 64 bit
  from 'https://downloads.haskell.org/~ghc/8.10.1/ghc-8.10.1-x86_64-unknown-mingw32.tar.xz'
Progress: 100% - Completed download of C:\ProgramData\chocolatey\lib\ghc\tmp\ghcInstall (407.68 MB).
Download of ghcInstall (407.68 MB) completed.
Hashes match.
C:\ProgramData\chocolatey\lib\ghc\tmp\ghcInstall
Extracting C:\ProgramData\chocolatey\lib\ghc\tmp\ghcInstall to C:\ProgramData\chocolatey\lib\ghc\tools...
C:\ProgramData\chocolatey\lib\ghc\tools
Extracting C:\ProgramData\chocolatey\lib\ghc\tools\ghcInstall~ to C:\ProgramData\chocolatey\lib\ghc\tools...
C:\ProgramData\chocolatey\lib\ghc\tools
PATH environment variable does not have C:\ProgramData\chocolatey\lib\ghc\tools\ghc-8.10.1\bin in it. Adding...
Hiding shims for 'C:\ProgramData\chocolatey\lib\ghc\tools'.
Environment Vars (like PATH) have changed. Close/reopen your shell to
 see the changes (or in powershell/cmd.exe just type `refreshenv`).
 The install of ghc was successful.
  Software installed to 'C:\ProgramData\chocolatey\lib\ghc\tools'

haskell-dev v0.0.1 (forced) [Approved]
haskell-dev package files install completed. Performing other installation steps.
 The install of haskell-dev was successful.
  Software install location not explicitly set, could be in package or
  default install location if installer.

Chocolatey installed 2/2 packages.
 See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).

Haskell platform installation makes changes to Environment variables. Please close PowerShell or run below command to take environment variable changes.

PS C:\WINDOWS\system32> refreshenv
Refreshing environment variables from the registry for cmd.exe. Please wait...Finished..

Now Haskell platform is installed in windows successfully, You are ready to enjoy writing a Haskell code.

Setup Haskell platform on Ubuntu and Linux

Haskell platform comes with installed packages from a repository for each version of Operating system

for `Linux debian``

sudo yum install haskell-platform

for [ubuntu](https://packages.ubuntu.com/search?keywords=haskell-platform)

sudo apt-get install haskell-platform

For [fedora linux] (https://admin.fedoraproject.org/pkgdb/package/haskell-platform/)

sudo dnf install haskell-platform

Check Haskell compiler -GHC, cabal installed or not

you can install either Haskell platform for quick and easy installation or you can  use individual packages

Please issue the below command ghc command and cabal command

B:\haskell>ghc --version
The Glorious Glasgow Haskell Compilation System, version 8.10.1

B:\haskell>cabal --version
cabal-install version 3.2.0.0
compiled using version 3.2.0.0 of the Cabal library

Reference

Similar Posts