追加のフォームフィールドを作成する方法についてオンラインで調査しました。私が使用している方法は、このサイトから来ています。
http://mrngoitall.net/blog/2013/10/02/adding-form-fields-dynamically-in-angularjs/
つまり、基本的に私がやろうとしているのは、データを入力することです。しかし、特定の人がいくつのデータポイントを入力したいのかわかりません。願い。
タグにこれがあります:
<script>
function AngularCtrl($scope) {
function Controller($scope) {
$scope.master = {};
$scope.update = function(user) {
$scope.master = angular.copy(user);
};
$scope.reset = function() {
$scope.user = angular.copy($scope.master);
};
$scope.reset();
}
$scope.choices = [{id: 'choice1'}];
$scope.addNewChoice = function() {
var newItemNo = $scope.choices.length+1;
$scope.choices.push({'id':'choice'+newItemNo});
};
$scope.showAddChoice = function(choice) {
return choice.id === $scope.choices[$scope.choices.length-1].id;
};
$scope.showChoiceLabel = function (choice) {
return choice.id === $scope.choices[0].id;
}
}
</script>
次に、これをタグに入れます:
<div class="form-group" ng-controller="Controller" data-ng-repeat="choice in choices">
<form novalidate class="simple-form">
Title of Chart: <input type="text" ng-model="chart.title" /><br />
Series Name: <input type="text" ng-model="chart.series" /><br />
Series Data: <input type="text" ng-model="series.data" /><br>
<label for="choice" ng-show="showChoiceLabel(choice)">Choices</label>
<button ng-show="showAddChoice(choice)" ng-
click="addNewChoice()">Add another choice</button>
<input type="text" ng-model="choice.name" name="" placeholder="Enter
a new data point">
<br>
<button ng-click="reset()">RESET</button>
<button ng-click="update(user)">SAVE</button>
</form>
</div>
ご覧のとおり、4 つのフォーム フィールドがあります。新しいフォーム フィールドを追加する選択肢が欲しい。ボタンはありますが、ボタンをクリックして別のフォームフィールドを追加すると; それは動作しません。それは同じままです。
タグに入っているものが少しずれているのではないかと思っていました。
お手伝いありがとう。これに何時間も苦労しています。