简体   繁体   English

无法通过字体真棒标签使单选按钮在ng-repeat中工作

[英]Can't get Radio Buttons to work in ng-repeat with font-awesome labels

I am struggling with getting some Font Awesome labels to work with radio buttons in an AngularJS ng-repeat. 我正在努力让一些Font Awesome标签与AngularJS ng-repeat中的单选按钮一起使用。 I know there is an issue with the $scope inside ng-repeat, and I have copied the examples of several work-arounds that mentioned using $parent , but none of the fixes have seemed to work for me thus far. 我知道ng-repeat中的$scope存在问题,并且我已经复制了使用$parent提到的几种变通方法的示例,但是到目前为止,这些修复程序似乎都对我没有用。 I want row clicking to still toggle the radio buttons as well. 我希望单击行仍可以切换单选按钮。

JSFIDDLE: http://jsfiddle.net/U3pVM/16692/ JSFIDDLE: http : //jsfiddle.net/U3pVM/16692/

HTML 的HTML

<div ng-app>
    <div ng-controller="TodoCtrl">
        <div class="container-fluid">
            <div class="row" ng-repeat="i in integrations" ng-click="$parent.isChecked = !$parent.isChecked">
                <div class="col-xs-1">
                    <input id="int{{$index}}" type="radio" ng-model="$parent.isChecked" name="radiointegration" ng-value="i.isChecked" />
                    <label for="int{{$index}}"></label>
                </div>
                <div class="col-xs-6" style="padding-top:10px">{{i.text}}</div>
                <div class="col-xs-5" style="padding-top:10px">{{i.isChecked}}</div>
            </div>
        </div>
    </div>
</div>

JS JS

function TodoCtrl($scope) {
    $scope.integrations = [{
        text: 'one',
        isChecked: false
    }, {
        text: 'one',
        isChecked: false
    }, {
        text: 'one',
        isChecked: false
    }, {
        text: 'one',
        isChecked: false
    }, {
        text: 'one',
        isChecked: false
    }];
}

CSS 的CSS

.row:nth-of-type(even) {
    background: #f3f8fe;
}
input[type=radio] {
    display: none;
}
/* to hide the radio itself */

input[type=radio] + label:before {
    font-family: FontAwesome;
    display: inline-block;
}
input[type=radio] + label:before {
    content: "\f1db";
}
/* unchecked icon */

input[type=radio] + label:before {
    letter-spacing: 10px;
}
/* space between radio and label */

input[type=radio]:checked + label:before {
    content: "\f00c";
    color: $harmonyColorGood
}
/* checked icon */

input[type=radio]:checked + label:before {
    letter-spacing: 5px;
}
/* allow space for check mark */

label {
    margin-top: 7px;
    margin-left: 10px;
    font-size: 25px;
}
label:hover,
.row:hover {
    cursor: pointer;
    background: #f5f5f5;
}

Somehow you handled your radio buttons like checkboxes. 您以某种方式处理了复选框之类的单选按钮。

I've removed some unnecessary variables in your fiddle, please check if this is the effect you need? 我在您的小提琴中删除了一些不必要的变量,请检查这是否是您需要的效果?

<div class="row" ng-repeat="i in integrations">
    <div class="col-xs-1">
        <input id="int{{$index}}" type="radio" ng-model="$parent.checked" name="radiointegration" ng-value="i.text" />
        <label for="int{{$index}}"></label>

fiddle 小提琴

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

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