使用 angular 从元素数组创建单选按钮列表
Create an radio button list from array of elements using angular
我想使用 angular js 从元素数组创建单选按钮列表
ng-重复。
任何示例都会有所帮助,谢谢
这是一个简单的例子
<!doctype html>
<html ng-app="myApp">
<head>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.5/angular.min.js"></script>
<script src="script.js"></script>
</head>
<body ng-controller="myCtrl">
<label ng-repeat="element in elements">
<input type="radio" ng-value="element"/ >
{{element}}
</label>
</body>
</html>
angular.module('myApp', [])
.controller('myCtrl', ['$scope', function($scope) {
$scope.elements = [1,2,3,4,5];
}]);
Plunkr
http://plnkr.co/edit/hNI5kjMHW6G9kSUeJtOp?p=preview
使用指令 ng-app
和 ng-controller
将控制器与视图连接起来。在您的控制器中,包括 $scope
作为依赖项,然后在其上设置一个包含元素数组的变量。
在标签元素上使用ng-repeat
,并用Angular表达式插入元素的值。
希望对您有所帮助。
我想使用 angular js 从元素数组创建单选按钮列表 ng-重复。
任何示例都会有所帮助,谢谢
这是一个简单的例子
<!doctype html>
<html ng-app="myApp">
<head>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.5/angular.min.js"></script>
<script src="script.js"></script>
</head>
<body ng-controller="myCtrl">
<label ng-repeat="element in elements">
<input type="radio" ng-value="element"/ >
{{element}}
</label>
</body>
</html>
angular.module('myApp', [])
.controller('myCtrl', ['$scope', function($scope) {
$scope.elements = [1,2,3,4,5];
}]);
Plunkr
http://plnkr.co/edit/hNI5kjMHW6G9kSUeJtOp?p=preview
使用指令 ng-app
和 ng-controller
将控制器与视图连接起来。在您的控制器中,包括 $scope
作为依赖项,然后在其上设置一个包含元素数组的变量。
在标签元素上使用ng-repeat
,并用Angular表达式插入元素的值。
希望对您有所帮助。