1

I wanted to create a radio button list from an array of elements using angular js ng-repeat.

Any example will help, thanks

1 Answer 1

3

Here's a simple example

<!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

Use the directives ng-app and ng-controller to connect your controller with the view. In your controller, include $scope as a dependency and then set a variable on it containing an array of elements.

Use ng-repeat on the label element, and insert the value of the element with Angular expressions.

Hope this helps.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.