效果图:
点击li中的radio,选中li中的文字;
点击li中的文字,选中li中的radio;
点击li中的radio,选中li中的文字;
点击li中的文字,选中li中的radio;
![](https://i-blog.csdnimg.cn/blog_migrate/3c8f4925ff22226b053379267a0d4ee3.png)
<script type="text/javascript">
var app=angular.module('app',[]);
app.controller('mainController',['$scope',function($scope){
//
$scope.conditions=[
{name:"axxxxx",age:"34"},
{name:"bxxxxx",age:"19"},
{name:"cxxxxx",age:"25"},
{name:"dxxxxx",age:"34"},
{name:"exxxxx",age:"19"},
{name:"fxxxxx",age:"25"},
{name:"gxxxxx",age:"22"},
{name:"hxxxxx",age:"25"},
{name:"ixxxxx",age:"19"},
{name:"jxxxxx",age:"43"},
{name:"kxxxxx",age:"28"}
];
$scope.spanRadioChecked=false;
//radio
$scope.radioClickFun=function(con){
$scope.flag=con;
}
//span
$scope.spanFun=function(con){
$scope.flag=con;
}
}]);
//指令:点击时“选中”、获取值、“背景变色”
app.directive('selectOnClick',['$window',function($window) {
return {
restrict:'A',
link: function(scope, element, attrs) {
element.on('click',function(){
alert(element.html());
});
}
};
}]);
</script>
<div ng-controller="mainController">
<ul style="height:110px; border: 1px solid #dddddd;overflow-y: scroll;">
<li ng-repeat="con in conditions" ng-model="flag">
<input type="radio" name="conRadio" ng-click="radioClickFun(con.name)" ng-checked="con.name==flag"/>
<span ng-click="spanFun(con.name)" ng-class="{'spanRadioChecked':con.name==flag}">{{con.name}}</span>
</li>
</ul>
</div>