angularjs - How to call the value when ng-model with ng-repeat is used? Angular JS -


i have problem of ng-model not geting called in controller if use ng-repeat. can see below, in sports section, sports value undefined when form submitted in controller demands, whatever input field meaning gets value. tried identify id not work well.

<form ng-submit="senddetails(sports, demands)" ng-class="form-horizontal" enctype="multipart/form-data"> <div class="row">     <div class="form-group col-md-6">         <label class="control-label col-sm-2">sports:</label>         <input class="form-control" ng-model="sports" ng-repeat="sports in selectedsports" type="text" disabled/>     </div> </div> <div class="row">     <div class="col-md-6">         <input class="form-control" ng-model="demands" type="text"/>     </div>     <div class="col-md-6">         <button class="btn btn-default" type="submit">submit</button>     </div> </div> </form> 

angular.factory('sportsfactory', function($http) { return {     postadministrationentries: function ($sports, $demands){         var fd = new formdata();         fd.append('sports', $sports);         fd.append('demands', $demands);         return $http.post('/senddetails', fd,{         headers: { 'content-type': undefined }         });     } } 

controller

$scope.sportsvalues =[]; $scope.senddetails = function($sports, $demands){     if($demands.length > 0 ){         var senddetailspromise = sportsfactory.senddetails($sports, $demands);         senddetailspromise.success(function (data){             $sportsvalues = data; }; 

it's because each loop through assigning same model each time. need use $index of loop in combination model:

<input class="form-control"   ng-model="sports[$index]"   ng-repeat="sports in selectedattributes track $index"   type="text" disabled /> 

although i'm sure realise being disabled, input never going changed model give (assuming it's not empty).


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -