问题描述
我正在为表单字段使用 angular 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.
使用相同的原则为非必填字段添加 (可选)
文本.
EDIT : use the same principle to add your (optional)
text for non required fields.
这篇关于如何从 Angular Material 的必填字段中删除星号并在可选标签的标签旁边添加(可选)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!