私はこのフォームをユーザーが記事をアップロードし、いくつかの共著者を追加するオプションを持っています。共著者を追加したい場合、彼は他のユーザのリストを含むドロップダウンメニューを動的に生成するボタンをクリックする。 AngularJSで動的に生成されたドロップダウンの選択値を取得
問題
は私が動的にそれらの選択メニューを生成していますということですので、それらのそれぞれが異なるng-model.Hereは、コントローラからのコードである必要があります。$scope.numberOfCoauthors = 0;
$scope.addCoauthors = function() {
$scope.index = "input_" + $scope.numberOfCoauthors;
console.log("Scope.model : " + $scope.index);
var $div = $("<p> Coautor: </p> <select ng-model='" + $scope.index + "'" +
" ng-options='user.username for user in allUsers' </select>" +
"<pre> {{ " + $scope.index + " | json }} </pre>")
var target = angular.element(document.querySelector('#coauthors'));
angular.element(target).injector().invoke(function($compile) {
var addedSelect = angular.element(target).scope();
target.append($compile($div)(addedSelect));
//$scope.$apply();
});
$scope.numberOfCoauthors++;
}
$scope.getSelectedValues = function() {
if($scope.numberOfCoauthors > 0) {
for(i=0; i<$scope.numberOfCoauthors; i++) {
var inputName = "input_"+i;
console.log(inputName);
console.log($scope.inputName);
}
}
}
私が取得しようとしています$ scope.inputName私は定義されていないので、これらのモデルは実際にスコープに追加されていないと思いますが、実際に追加する方法はわかりません。
を私はjQueryのすべてを廃棄して、コントローラからDOMに要素を追加することをお勧めしますし、簡単に使用することになり非表示にすることができます私が仮定しているauthorsコレクションのng-repeatは、オブジェクトの配列です...そうでなければ、それはすべきです。 – jbrown