angularjs - getting value of inputs created by ng-repeat -
i created radiobutton input struggling values of selected inputs.
this radiobuttons input created
<ul ng-repeat="item in riskmodel"> <li> <input type="radio" name="rdbrisk" ng-value="{{item.value}}" /> {{item.text}} </li> </ul>
and ng-model definiton in controller
$scope.riskmodel = [ { id: 0, text: "a", value: "" }, { id: 1, text: "b risk", value: "yr" }, { id: 2, text: "c risk", value: "or" }, {id:3,text:"d risk",value:"dr"} ]
i want take selected value , send function parameter far failed results.
declare ng-model
variable object $scope.radiomodel = {};
var myapp = angular.module('myapp',[]); myapp.controller('greetingcontroller', ['$scope', function($scope) { //$scope.radiomodel = {}; $scope.riskmodel = [ { id: 0, text: "a", value: "" }, { id: 1, text: "b risk", value: "yr" }, { id: 2, text: "c risk", value: "or" }, {id:3,text:"d risk",value:"dr"} ] $scope.changevalue = function(value){ console.log(value.selected); } }]);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> <body ng-app="myapp"> <div ng-controller="greetingcontroller" ng-init="radiomodel={}"> selected value : {{radiomodel.selected}} <ul ng-repeat="item in riskmodel"> <li> <input type="radio" ng-model="radiomodel.selected" name="rdbrisk" ng-value="item.value" ng-change="changevalue(radiomodel)"/> {{item.text}} </li> </ul> </div> </body>
Comments
Post a Comment