javascript - How do I get all selected dropdown values in one model angular js -
<tr ng-show="show"> <td> <select class="form-control" data-ng-model="mymodel.firstname" data-ng-options="firstname.name name in myproperties" ng-show="editmode" style="width:100%; "> <option value="" style="margin-left:25px">-select first name-</option> </select> </td> <td> <select class="form-control" data-ng-model="mymodel.lastname.selectedoption" ng-options="lastname.name lastname in mymodel.lastname.options" ng-show="editmode" style="width:100%; "> <option value="" style="margin-left:25px">-select last name-</option> </select> </td> <td> <a href="" class="glyphicon glyphicon-save buttons" data-placement="left" ng-click="editmode=!editmode;save("need pass model contain both above values")" ng-show="editmode"></a> </td>
how both dropdown (dynamically generated) values in single model pass save method , in index,js
index.js
$scope.save = function (mymodel) { var alldataobj = { firstname: mymodel.firstname, lastname: mymodel.lasttname };
have @ code might useful
<doctype html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script> </head> <body ng-app="myapp" data-ng-controller="homectrl"> <select ng-model="opt.first" ng-options="obj.code obj.code obj in opts"> <option value="">select</option> </select> <select ng-model="opt.second" ng-options= "obj.code obj.code obj in opts1"> <option value="">select</option> </select> <button ng-click="save(opt)">save</button> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script> <script> angular.module('myapp', []); angular.module('myapp').controller('homectrl', ['$scope', function($scope) { $scope.opts = [ { "code" : "abc", "num" : ["246810","4681012","681012"] }, { "code" : "def", "num" : ["13579","357913","5791315"] } ] ; $scope.opts1 = [ { "code" : "abc", "num" : ["246810","4681012","681012"] }, { "code" : "def", "num" : ["13579","357913","5791315"] } ] ; $scope.save=function(model) { console.log("model==", model) var obj={}; obj.firstname=model.first; obj.lastname=model.second; console.log("first==", obj.firstname); console.log("last==", obj.lastname) } }]); </script> </body> </html>
Comments
Post a Comment