推送到嵌套 ng-repeat 中的数组
Push to array in nested ng-repeat
<!-- Angular.JS Form to JSON -->
var formApp = angular.module('formApp', []).controller('formController', ['$scope', function ContactController($scope) {
$scope.form = [];
$scope.milestone_subindicator = {data:'',year:'' , data:'',year:''
}
$scope.push_form = function(){
$scope.form.push({name:'',milestone:[]})
};
}]);
<!-- Form -->
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.22/angular.min.js"></script>
{{form}}
<button type="button" class="success button" ng-click="push_form()">Add</button><!-- Add form -->
<body ng-app="formApp" ng-controller="formController">
<div class="row" ng-repeat="f in form track by $index">
<input type="text" placeholder="G1" data-ng-model = "f.name"></input> // name of the orgranisation
<div class="row" ng-repeat = "mil in milestone_subindicator track by $index"> // milestones
<div class="medium-2 columns">
<label>Data
<input type="text" placeholder="data" ng-model="mil.data">
<input type="text" placeholder="year" ng-model="mil.year">
</label>
</div>
</div>
</div>
</body>
在上面的示例中,您可以看到 {{form}} 的输出,我需要将 mil in milestone_subindicator
的值放入 milestone array 中表格 。我不知道该如何实现?
将不胜感激:)
谢谢你们。终于,我找到了答案的解决方案。
var formApp = angular.module('formApp', []).controller('formController', ['$scope', function ContactController($scope) {
$scope.form = [];
$scope.milestone_subindicator = {data:'',year:'' , data:'',year:''
}
$scope.push_form = function(){
$scope.form.push({name:'',milestone:[]})
};
$scope.push_cat = function(index,data){
console.log(data);
$scope.form[index].milestone.push(data);
};
}]);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
{{form}}
<button type="button" class="success button" ng-click="push_form()">Add</button>
<body ng-app="formApp" ng-controller="formController">
<div class="row" ng-repeat="f in form track by $index">
<input type="text" placeholder="G1" data-ng-model = "f.name"></input>
<div class="row" ng-repeat = "mil in milestone_subindicator track by $index">
<div class="medium-2 columns">
<label>Data
<input type="text" placeholder="data" ng-model="mil.data">
<input type="text" placeholder="year" ng-model="mil.year">
</label>
</div>
<button ng-click="push_cat($parent.$index,mil)">add cat</button>
</div>
</div>
</body>
<!-- Angular.JS Form to JSON -->
var formApp = angular.module('formApp', []).controller('formController', ['$scope', function ContactController($scope) {
$scope.form = [];
$scope.milestone_subindicator = {data:'',year:'' , data:'',year:''
}
$scope.push_form = function(){
$scope.form.push({name:'',milestone:[]})
};
}]);
<!-- Form -->
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.22/angular.min.js"></script>
{{form}}
<button type="button" class="success button" ng-click="push_form()">Add</button><!-- Add form -->
<body ng-app="formApp" ng-controller="formController">
<div class="row" ng-repeat="f in form track by $index">
<input type="text" placeholder="G1" data-ng-model = "f.name"></input> // name of the orgranisation
<div class="row" ng-repeat = "mil in milestone_subindicator track by $index"> // milestones
<div class="medium-2 columns">
<label>Data
<input type="text" placeholder="data" ng-model="mil.data">
<input type="text" placeholder="year" ng-model="mil.year">
</label>
</div>
</div>
</div>
</body>
在上面的示例中,您可以看到 {{form}} 的输出,我需要将 mil in milestone_subindicator
的值放入 milestone array 中表格 。我不知道该如何实现?
将不胜感激:)
谢谢你们。终于,我找到了答案的解决方案。
var formApp = angular.module('formApp', []).controller('formController', ['$scope', function ContactController($scope) {
$scope.form = [];
$scope.milestone_subindicator = {data:'',year:'' , data:'',year:''
}
$scope.push_form = function(){
$scope.form.push({name:'',milestone:[]})
};
$scope.push_cat = function(index,data){
console.log(data);
$scope.form[index].milestone.push(data);
};
}]);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
{{form}}
<button type="button" class="success button" ng-click="push_form()">Add</button>
<body ng-app="formApp" ng-controller="formController">
<div class="row" ng-repeat="f in form track by $index">
<input type="text" placeholder="G1" data-ng-model = "f.name"></input>
<div class="row" ng-repeat = "mil in milestone_subindicator track by $index">
<div class="medium-2 columns">
<label>Data
<input type="text" placeholder="data" ng-model="mil.data">
<input type="text" placeholder="year" ng-model="mil.year">
</label>
</div>
<button ng-click="push_cat($parent.$index,mil)">add cat</button>
</div>
</div>
</body>