该JS Fiddle将提供有关代码的更好信息。
所选项目应过滤其他值,并且我将在列表项外部有一个按钮,该按钮会将所选值重新分配为null,以便显示所有列表项。
单击单选按钮,它应该隐藏其他元素。
控制器
var myApp = angular.module("repeat",["ngSanitize"]);
myApp.controller("repeatController", function($sce, $window, $scope){
$scope.test ="Controller is working fine";
$scope.lists=[{"name":"asdf","desc":"dummy text 1"},{"name":"wee","desc":"dummy text 2"},{"name":"fgs","desc":"dummy text 3"}]
});
的HTML
<li ng-repeat ="list in lists | filter:{name:selected}">
<label ng-click="selected = list.name">
<input type="radio">
{{list.name}}{{selected}}
</label>
</li>
如果我正确理解了您的需求,那么这里是JSFiddle以隐藏未单击的单选按钮:
HTML:
<div ng-app="repeat" ng-controller="repeatController">
<li ng-repeat ="list in lists" ng-hide="selected !== undefined && selected !== list.name">
<label ng-click="$parent.selected = list.name">
<input type="radio" name="selector" />
{{list.name}}-{{selected}}
</label>
</li>
</div>
JS:
var myApp = angular.module("repeat", []);
myApp.controller("repeatController", function($sce, $window, $scope){
$scope.test ="Controller is working fine";
$scope.lists=[{"name":"asdf","desc":"dummy text 1"},{"name":"wee","desc":"dummy text 2"},{"name":"fgs","desc":"dummy text 3"}]
});
根据建议,您还需要从小提琴中删除ngSanitize或将其也添加为文件(例如,添加此资源,但出于小提琴的目的,您不需要它https://cdnjs.cloudflare.com/ajax/ libs / angular.js / 1.4.1 / angular-sanitize.min.js)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句