我有一个标签,我想在需要字段时添加星号。我尝试过像这样应用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: " *"
}
任何解决方案?
答案 0 :(得分:3)
我真的不知道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>
(我将代码缩减到代码段所需的最小值)