Tutorialsplane

Angular Material Chips


Angular Material Chips: <md-chips> is an input component which is used to create list of strings or objects. The list items are displayed as ‘chips’. Angular Material Provides beautiful and smooth chips functionality. Here in this tutorial we are going to explain how you can create chips using the <md-chips> component. You can also use online demo to edit and run the code online.


Angular Material Chips Example

Let us first create a very basic chip using –

Angular Material Chips Example:


   
      
      
      
      
      
      
	  
	 
            
   
    
   <div ng-controller="myController as ctrl" layout="column" ng-cloak="">
    <md-content>
    <section layout="row" layout-sm="column" layout-align="center center" layout-wrap="">
     <h2 class="md-title">Use the default chip template.</h2>

    <md-chips ng-model="ctrl.fruitNames" readonly="ctrl.readonly" md-removable="ctrl.removable"></md-chips>

    </section>
    </md-content>
   </div>
   
   

Try it »

In the above example we have create an array of fruits which has been assigned to the input as default chips. You can add other chips also. If you run the above example it will produce the output something like this –

Options Available

Following options are available that be added easily if you need them-


Learn More

Let us have some example and demo about the Angular Material Chips.


Use Custom Template

Here in this tutorial we have created a custom template.md-chip-template is used to create a custom template for chips. Here is an example of Custom Chips –

Using Custom Template Example

 
<h2 class="md-title">Using a custom chip template.</h2>
    

Try it »

Editable Chips

You can make chips editable using the attribute md-enable-chip-edit=”true”.

Editable chips Example

 
<h2 class="md-title">Editable chip Example.</h2>
    

Note: Editing functionality works with only basic templates.

Add placeholder

If you want to add the placeholder you can use the attribute – placeholder,secondary-placeholder. Here is an example to add placeholders in Chips-

Add placeholder to chips: Example

 
 <md-chips ng-model="ctrl.tags" readonly="ctrl.readonly" md-removable="ctrl.removable" placeholder="Add a name" delete-button-label="Remove Name" delete-hint="Press delete to remove name" secondary-placeholder="+Name">
</md-chips>

Try it »

If you run the above example it will produce the following output-

Add Validation And Show Error Message

You can add validation and display error message simply as below –

Add Validation And Display Error Message: Example

 
 

Learn Angular Material