I have a label that I want to add an asterisk to if field is required. I have tried applying ng-class
like so
<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
.asterisk-if-mandatory {
content: " *"
}
Any solutions?
I have a label that I want to add an asterisk to if field is required. I have tried applying ng-class
like so
<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
.asterisk-if-mandatory {
content: " *"
}
Any solutions?
Share Improve this question asked Jun 5, 2018 at 13:56 LazioTibijczykLazioTibijczyk 1,9671 gold badge29 silver badges63 bronze badges 3-
As I don't know angular… What will be the rendered output of
ng-class="{'asterisk-if-mandatory': data[$index].mandatory}"
? – Takit Isy Commented Jun 5, 2018 at 13:59 -
2
put it on an after:
.asterisk-if-mandatory:after { content: " *"; display:inline-block; }
If your ng class is applied – Pete Commented Jun 5, 2018 at 14:00 - Great stuff @Pete! – LazioTibijczyk Commented Jun 5, 2018 at 14:01
1 Answer
Reset to default 5I don't really know Angular…
But I would say you can do something like this, using pseudo-element ::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)
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745096868a4611032.html
评论列表(0条)