简体   繁体   English

如果需要该字段,请在标签上添加星号

[英]Add an asterisk to a label if field is required

I have a label that I want to add an asterisk to if field is required. 如果有必填字段,我有一个标签想添加一个星号。 I have tried applying ng-class like so 我已经尝试过像这样应用ng-class

<div class="col-xs-12 top5"  ng-if="(activity.itemType=='TEXTAREA')">
     <label class="col-xs-3 control-label text-right" for="act4{{$index}}"
            ng-class="{'asterisk-if-mandatory': data[$index].mandatory}">{{activity.itemLabel}}</label>
     <div class="col-xs-9">
         <textarea ng-model="activityItems[$index].value"
                   ng-required="data[$index].mandatory" cols="40" rows="6"
                   id="act4{{$index}}" name="txtComments" class="defaultTextareaInput"></textarea>
     </div>
</div>

and then css 然后css

.asterisk-if-mandatory {
    content: " *"
}

Any solutions? 有什么办法吗?

I don't really know Angular… 我不太了解Angular ...
But I would say you can do something like this, using pseudo-element ::after : 但是我想说,您可以使用伪元素::after来做类似的事情:

 label { border: 1px solid gray; padding: 4px 8px; } label.asterisk-if-mandatory::after { content: " *"; } 
 <label class="asterisk-if-mandatory">Item is mandatory</label> <label class="">Item is not mandatory</label> <label class="asterisk-if-mandatory">Item is mandatory</label> 

(I reduced the code to the minimum required for the snippet) (我将代码减少到了代码段所需的最低限度)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM