0

ng-repeat を使用してフォームを繰り返しています。繰り返しは新しい形を作ることです。ワンクリックですべてのフォームデータを送信したい。配列に複数の値を割り当てる方法を見つけることができません。

ここに私のフォームがあります:

<div id="check" ng-repeat="screen in screens">
                   <input type="hidden" name="scrnid" ng-model="screen.scrnid" value="{{ screen.scrnid }}" />
            <label>Name:</label>
            <input type="text" ng-model="screen.bdayname" placeholder="Name" ng-required/>
            <label>Date:</label>
            <input type="date" ng-model="screen.bdaydate" placeholder="Date" ng-required/>
            <br/>
               </div>

               <button class="btn" type="submit" ng-click="newBirthday()">Save</button>
</div>
<div class="container">
        <input type="button" class="btn" ng-click="createScreen()" /><i class="icon-plus"></i>Add
</div>

そしてそれは私のコントローラーです

app.controller('main', function($scope){ 

    $scope.screens = [{scrnid: "1"}];
    $scope.scrnid = 1;
    $scope.createScreen = function()
    {
            $scope.screens.push({scrnid: "" + ($scope.screens.length + 1)});            
    };

    $scope.bdays = [];        
    // Create the function to push the data into the "bdays" array

    $scope.newBirthday = function(){        

        $scope.bdays.push($scope.screens.length);  // how to push mutiple records in array dynamically

        $scope.screen.bdayname = '';
        $scope.screen.bdaydate = '';
    };
});

助けていただければ幸いです...

4

1 に答える 1

0

オブジェクトをbdayスコープ変数に格納するようにコードを編集しました

var app=angular.module("birthdayToDo",[]);


app.controller('main', function($scope){ 

   $scope.screens = [{scrnid: "1"}];
  $scope.scrnid = 1;
    $scope.createScreen = function(){
            $scope.screens.push({scrnid: "" + ($scope.screens.length + 1)});  

            console.log($scope.screens);          
        };

        $scope.bdays = [];        


    $scope.newBirthday = function(){

        for(i=0;i<$scope.screens.length;i++){
            $scope.bdays.push($scope.screens[i])
        }
        console.log($scope.bdays);


    };


    $scope.remove=function(item){ 
      var index=$scope.bdays.indexOf(item)
      $scope.bdays.splice(index,1);     
    }



});
于 2015-03-11T10:21:38.470 に答える