AngularJS | ng-value Directive

The ng-value Directive in AngularJS is used to specify the value of an input element. It is supported by <input> and <select> elements.

Syntax:

<element ng-value="expression"> Content ... </element> 

Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
    <head>
        <title>ng-value Directive</title>
        <script src=
        </script>    
        </head>
    <body ng-app="app" style="padding:20px">
      <h1 style="color:green;">GeeksforGeeks</h1>
      <h2 style="">ng-value Directive</h2>
      <p>Choose one:</p>
      <div ng-controller="geek">
          <div ng-repeat="l in sort">
           <input type="radio" ng-model="my.fav" ng-value="l" name="Sort"> {{l}}
          </div>
          <pre>Selected choice is: {{my.fav}}</pre>
      </div>
      <script>
      var app = angular.module("app", []);
      app.controller('geek', ['$scope', function ($scope) {
          $scope.sort = ['Merge Sort', 'Quick Sort', 'Bubble Sort'];
          $scope.my = { fav: 'Merge Sort' };
      }]);
        </script>
    </body>
</html>

chevron_right


Output:
ngvalue



My Personal Notes arrow_drop_up


If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.