Ng-Value-2

 

In this example id of the selected language with ng-value directive bind to the ctrl.selected and displayed below it when you select the language.

 
 
 
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Welcome to LearnKode - A code learning platform</title> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.min.js"></script> </head> <body ng-app="app"> <h3>Which is your favorite ?</h3> <div ng-controller="controllerName"> <label ng-repeat='item in list'> <input name="selected" type="radio" ng-model="ctrl.selected" ng-value="item.id"> {{item.name}} </label> <pre> Id of selected item's id is = {{ctrl.selected}} </pre> </div> <script> var app = angular.module("app", []); app.controller('controllerName', ['$scope', function ($scope) { $scope.ctrl = { selected: '1' }; $scope.list = [{ id: '', name: 'AngularJs' }, { id: '1', name: 'JavaScript' }, { id: 'Null', name: 'Bootstrap' }, { id: '""', name: 'Jquery' }]; }]); </script> </body> </html>
Output