数据未使用angularjs从service.js传递给spring控制器

时间:2015-05-27 12:42:23

标签: angularjs spring-mvc angularjs-scope

我无法将service.js中的ownerName名称和ownerTeam名称发送到Spring控制器。当我发送多个ownerName和ownerTeam时,只传递最后更新的值。请帮帮我。

CreateTask.html:

  <fieldset>
               <legend>Owners</legend>
               <div class="form-group" ng-repeat="owner in formData.owners">
                    <div class="col-md-2 " ><label for="ownerName" translate="task.form.ownerName">Name</label></div>

                    <div class="col-md-3 "><input type="text" class="form-control" id="owner.ownerName" placeholder="{{'task.form.ownerName.placeholder' | translate}}" ng-model="owner.ownerName"></div>

                    <div class="col-sm-1 "><img src="images/searchicon.png" width="23" height="23"/></div>
                    <div class="col-md-2"><label for="ownerTeamName" translate="task.form.ownerTeamName">Team</label></div>
                    <div class="col-md-3">
                    <select class="form-control" id="owner.ownerTeamName" placeholder="{{'task.form.ownerTeamName.placeholder' | translate}}" ng-model="owner.ownerTeamName" ng-options="opt as opt for opt in teamNames" ng-init="owner.ownerTeamName='Release Management'"">
                    </select>
                    </div>
                   <div class="col-sm-1 col-centered col-fixed"> <img src="images/plus.png" width="15" height="15" ng-click="addOwners()"/></div>
                   <br/><br/>
                   </div>
                </fieldset>



Controller.js


      $scope.owners=[{ownerName:"",ownerTeamName:""}];
      $scope.formData = {owners: [{ownerName:"",ownerTeamName:""}] };

      $scope.addOwners = function(){
            /*$scope.formData.owners.push({ownerName: $scope.formData.owners[0].ownerName, ownerTeamName: $scope.formData.owners[0].ownerTeamName });*/
            $scope.formData.owners.push({ownerName:'',ownerTeamName:''});
TaskCreationService.createNewTask({
"owners":$scope.formData.owners
      };

Service.js
releaseApp.factory('TaskCreationService', function ($rootScope, $http) {

      var owners=[];
      var ownerName=[];
      var ownerTeamName =[];

    return {

      createNewTask: function (param) {
              var ownerList = param.owners;
            for(var i = 0; i < ownerList.length; i++){
                  ownerName=ownerList[i].ownerName;
                  ownerTeamName = ownerList[i].ownerTeamName;

            }

            var data ={                                                 
                              "owners":[{       
                                    "ownerName":{
                                          "name":ownerName
                                          },
                                    "ownerTeam":{
                                          "name":ownerTeamName
                                          }
                              }]



            }
            $http.post('taskCreation/createNewTask', data).success(function (data, status) {     
                  console.log('success');
                  alert('Task Created Successfully');
            }).error(function(data, status) {
                console.log((data || 'No task created') + ': ' + status);
            });

        }


   }


});

0 个答案:

没有答案