Skip to content
Related Articles

Related Articles

Improve Article

AngularJS | ng-value Directive

  • Last Updated : 05 Apr, 2019

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:




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

Output:
ngvalue




My Personal Notes arrow_drop_up
Recommended Articles
Page :