How to remove an asterisk from a required field in Angular Material

When you define an input field as required in an angular material, it automatically adds an asterisk after the label. I found many questions asking how to add them, but not one how to remove it. It seems that this was not a default at the time they requested it, but according to this link this is now the default behavior (I use the version available at https://github.com/angular/material **). How to remove it and get the same behavior as shown here by @Styx.

** By the time I had this problem, I thought I was using the latest version (v. 1.0.5), but in fact I was using the main version, which could have an asterisk function.

+5
source share
2 answers

Although this feature is not yet installed in 1.0.5, the release notes ...

I looked at this commit , and this is probably what we are looking for:

mdc non-asterisk

 <input md-maxlength="30" required md-no-asterisk name="description" ng-model="project.description"> 

This is a closed issue for this function, status says 'needs: merge'

+9
source

When using mat-form-field Angular Materials you can add hideRequiredMarker

 <mat-form-field hideRequiredMarker> <input required placeholder="type here"> </mat-form-field> 

Credits @ shivek-parmar How to remove an asterisk from a required field in Angular Material and add (optional) next to the label for optional labels

0
source

Source: https://habr.com/ru/post/1243243/


All Articles