angularjs - How to send data to server from a select in a form -


i have controller:

  $scope.disciplines = disciplines;   $scope.discipline = disciplines[0]; 

it's array.

i have in form:

  <form class="form-horizontal" ng-submit="submit()"  method="post">     <input type="text" name="prj_title"  ng-model="project.prj_title" class="form-control" id="title">     <select id="discipline" class="form-control" name="prj_discipline" ng-model="discipline" ng-options="d d in disciplines"></select>     <input type="submit" class="btn btn-block btn-success btn-lg" value="ansök"> </form> 

and post:

      $scope.submit = function(){         $http({           method  : 'post',           url     : '/api/project',           data    : $.param($scope.project),  // pass in data strings           headers : { 'content-type': 'application/x-www-form-urlencoded' }  // set headers angular passing info form data (not request payload)         })         .success(function(data, status) {           ...           }         })       }; 

the first input works. server receives prj_title:.

but select tag not work.

name=discipline not seem have effect. value not sent server. have read docs , name-property should valid on select tag. want select tag send prj_discipline:

what doing wrong?

you can change select ng-model input,

<select id="discipline" class="form-control" name="prj_discipline"  ng-model="project.prj_discipline" ng-options="d d in disciplines"></select> 

basically need names form validation, posting $scope.project object has no property name prj_discipline, if bind select model project.prj_discipline work...


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -