html - How to get selected text,value from the dropdown and assign into list object in angularjs -


here i'm using angularjs web api. want selected dropdown list values , assign list object , it'll save db. here code.

selectmodule.controller("selectstatecontroller", function ($scope) {  $scope.ilbasicinfodto.pyrornonresidencystateinfo.taxpayerearnedincomefromotherstate = { stateid: 10, statename: 'illinois' }, { stateid: 11, statename: 'new york' }, { stateid: 12, statename: 'michigan' }, { stateid: 13, statename: 'georgia' }, { stateid: 14, statename: 'california' };    $.ajax({        url: serviceurl + 'il/persistilbasicinfo',        datatype: "json",        type: "post",        async: true,                    data: json.stringify({                  userid: userid,                  taxreturndata:                     {                         userdataid: userdataid,                         taxdata: json.stringify($scope.ilbasicinfodto),                         istaxmetercall: false                     },              }),              contenttype: "application/json; charset=utf-8",              error: function (jqxhr, textstatus, errorthrown) {                  errorhandling(jqxhr, errorthrown);              },              success: function (data, textstatus) {                  if (data != null) {                    }                }          })  });
<select id="ddlspouseeearnedincomefromotherstate0" ng-model="ilbasicinfodto.pyrornonresidencystateinfo.taxpayerearnedincomefromotherstate">  <option value="">--select--</option>  <option ng-repeat="tstatesexceptil in taxpayerstatesexceptilandreciprocalstates" ng-value="tstatesexceptil.stateid">{{tstatesexceptil.statecode}}</option>  </select>

in order selected text , value, pass complete object ng-value:

<select id="ddlspouseeearnedincomefromotherstate0" ng-model="ilbasicinfodto.pyrornonresidencystateinfo.taxpayerearnedincomefromotherstate">   <option value="">--select--</option>  <option ng-repeat="tstatesexceptil in taxpayerstatesexceptilandreciprocalstates" ng-value="tstatesexceptil">{{tstatesexceptil.statecode}}</option> </select> 

now can text , value $scope variable have binded ng-model i.e $scope.ilbasicinfodto.pyrornonresidencystateinfo.taxpayerearnedincomefromotherstate

text as: $scope.ilbasicinfodto.pyrornonresidencystateinfo.taxpayerearnedincomefromotherstate.statecode

value as: $scope.ilbasicinfodto.pyrornonresidencystateinfo.taxpayerearnedincomefromotherstate.stateid


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -