我有一个标签,如果字段是必需的,我想添加一个星号。我试过像这样应用 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>
然后是CSS
.asterisk-if-mandatory {
content: " *"
}
有什么解决办法吗?
最佳答案
我真的不知道 Angular...
但我会说你可以做这样的事情,使用伪元素 ::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>
(我将代码减少到代码片段所需的最低限度)
关于javascript - 如果需要字段,请在标签上添加星号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50701958/