如何从Angular Material的必填字段中删除星号,并在标签旁边添加(可选)以添加可选标签 [英] How do I remove asterisk from required field in Angular Material and add (optional) beside label for optional labels

查看:146
本文介绍了如何从Angular Material的必填字段中删除星号,并在标签旁边添加(可选)以添加可选标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将Form 2材质设计为表单字段.因此,所有不需要的字段都以星号出现,这是我不希望的.此外,对于非必填字段,我希望在标签旁边的方括号中显示可选文本.

I am using angular 2 material design for form fields. So with that every required fields appear with asterisk which i don't want.Also, for non-required fields, i want an optional text to be appear in brackets next to the label.

我正在使用下面的方法来实现它,但是那没有用.

I am using something like below to achieve it but that's not working.

我的代码-

<md-input required md-no-asterisk id="" placeholder="First Name" [(ngModel)]="" ngControl="txtFirstName" #firstName="ngModel"></md-input>

当我删除md-input的开始和结束标签而仅使用输入标签时,星号消失了,但是一些默认的文本显示为该字段的值.

When I am removing md-input starting and end tag and just using input tag then the asterisk goes away but some default text called appears as a value of the field.

我想使用必填字段和可选字段作为标签.

I want to use required and optional fields as a label.

任何帮助将不胜感激.

推荐答案

因此,根据我的评论,我查看了Angular Material的网站.

So, following my comment, I looked on Angular Material's website.

看:

有一个after组件,其中包含星号.用您自己的CSS重写该类以摆脱它.

as you can see, there's an after component, which contains the asterisk. Override this class with your own CSS to get rid of it.

使用相同的原理为非必填字段添加(optional)文本.

EDIT : use the same principle to add your (optional) text for non required fields.

这篇关于如何从Angular Material的必填字段中删除星号,并在标签旁边添加(可选)以添加可选标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆