javascript - how to get selected value from Drop-down, if drop-down is binded with keys of json -
i new angularjs, have binded column names(keys key value pair) select list , want key name on alter of selection of select. select list showing:
name, snippet , age
and on selection alter want selected text of select. please help here code:
<!doctype html>
<div ng-controller="hellocontroller"> <h2>hello {{helloto.title}} !</h2> <select ng-options="key (key,val) in phones[0]" ng-change="changevalue(key)" ng-model="phones"></select> </div> <script> angular.module("myapp", []) .controller("hellocontroller", function ($scope) { $scope.helloto = {}; $scope.helloto.title = "world, angularjs"; $scope.phones = [ { 'name': 'nexus s', 'snippet': 'fast got faster nexus s.', 'age': 1 }, { 'name': 'motorola xoom™ wi-fi', 'snippet': 'the next, next generation tablet.', 'age': 2 }, { 'name': 'motorola xoom™', 'snippet': 'the next, next generation tablet.', 'age': 3 } ]; $scope.changevalue = function (selectedval) { alert(selectedval.name); }; }); </script>
<select ng-options="key key (key,value) in phones[0]" ng-change="changevalue()" ng-model="selectedval"></select>
and controller:
angular.module("myapp", []) .controller("hellocontroller", function ($scope) { $scope.helloto = {}; $scope.helloto.title = "world, angularjs"; $scope.selectedval = ''; $scope.phones = [{ 'name': 'nexus s', 'snippet': 'fast got faster nexus s.', 'age': 1 }, { 'name': 'motorola xoom™ wi-fi', 'snippet': 'the next, next generation tablet.', 'age': 2 }, { 'name': 'motorola xoom™', 'snippet': 'the next, next generation tablet.', 'age': 3 }]; $scope.changevalue = function() { console.log($scope.selectedval); }; });
it's right in documentation actually...
here's plunker.
javascript jquery html json angularjs
No comments:
Post a Comment