简体   繁体   English

如何在AngularJS中按名称计算单选按钮的数量

[英]how to count number of radio buttons by name in AngularJS

I want to know how to get number of radio buttons by name in AngularJS using a directive. 我想知道如何使用指令在AngularJS中按名称获取单选按钮的数量。

<label ng-repeat="elements in [1,2,3,4,5,6,7]">
      <input type="radio" name="phone" ng-model="phone" value="example"> 
</label>

<!--Directive by name (phone), number of radio buttons is 7-->

<label ng-repeat="elements in [1,2,3,4,5,6,7,8,9]">
      <input type="radio" name="OS" ng-model="OS" value="example"> 
</label>

<!--Directive by name (OS), number of radio buttons is 9-->

Probably assign some value on the scope: $scope.myList = [1,2,3,4,5,6,7,8,9]; 可能在范围上分配一些值: $scope.myList = [1,2,3,4,5,6,7,8,9]; . And show the length of the list on the view like: {{ myList.length }} . 并在视图上显示列表的长度,例如: {{ myList.length }}

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

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