简体   繁体   English

Angular Js-检查内部无线电输入时的格式化标签

[英]Angular Js - formating label when inner radio input is checked

I'm dealing with this case where I have a label tag wraps around the radio input button, something like: 我正在处理这种情况,我的标签标签环绕在单选按钮上,例如:

<label>
     <input type="radio" ng-model="question.value" value="{{option.value}}">
</label>

The label tag is the one that gets formatted for view while the radio button is hidden. 标签标记是在单选按钮隐藏时被格式化以供查看的标记。 When ng-model == value , a certain radio button gets checked automatically and this is happening in my app, no problem at all. ng-model == value ,某个单选按钮会自动检查,这在我的应用程序中正在发生,完全没有问题。

The problem is, I want to format the label tag when this happens. 问题是,发生这种情况时,我想格式化标签标签。 Normally the label is formatted by an onclick event, but this is not an event so I'm not sure how I would solve this in JavaScript. 通常,标签是通过onclick事件格式化的,但这不是事件,因此我不确定如何在JavaScript中解决此问题。 CSS styling is not an option because it can't select parent element. CSS样式不是一种选择,因为它不能选择父元素。

use ng-class 使用ng-class

<label ng-class="{'class-name':question.value==option.value">
     <input type="radio" ng-model="question.value" value="{{option.value}}">
</label>

in CSS 在CSS中

.class-name{
   color:green;
}

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

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