0
我得到了這個問題如何將所有選中的單選按鈕的數據從模式窗口發送到父級控制器?
在我宣佈ID列表中mainController,叫ALLUSERS,我送他們到模態窗口與單選按鈕來顯示,每個單選按鈕具有不同的名稱,以使多選擇,但都具有相同的ng模型,selectedUsers,即。
一旦我選擇了幾個顯示的用戶,我按下OK按鈕,誰觸發$ scope.ok函數,在for循環中,我想獲得所有我選擇的用戶,並將它們推入列表中, selectedUserIds。
但是,一旦我運行代碼,我selectedUsers列表是空的(但我選擇了3個用戶)
所以,在最後,有兩個可能的問題。
- 我從他們的單選按鈕和獲取數據的編碼是錯誤
- 我甚至不從模態窗口將數據發送到主控制器
我希望你能幫助我...
這裏是代碼:
mainController.js
$scope.allUsers = [0,1,2,3,4,5,6,7,8,9,11,12,13,14,15,16,17,18,19,20];
$scope.selectedUserIds = [];
$scope.ok = function() {
angular.forEach($scope.selectedUsers, function(user) {
$scope.selectedUserIds.push(user);
});
}
$scope.open = function() {
var modalInstance = $uibModal.open({
scope: $scope,
templateUrl: '../Popup.html',
resolve: {
allUsers: function() {
return $scope.allUsers;
}
}
});
}
的index.html
<button ng-click="open()">Share Script</button>
Popup.html
<div class="modal-header">
<h3 class="modal-title">Share the Script</h3>
</div>
<div class="modal-body">
<h4>Check the users who you want to share the selected script!</h4>
<ul>
<label ng-repeat="user in allUsers">
<input type="radio" name={{user}} ng-value="{{user}}" ng-model="selectedUsers"
/> {{user}} user
</label>
</ul>
</div>
<div class="modal-footer">
<button class="btn btn-default" type="button" ng-click="ok();$close()">Ok</button>
<button class="btn btn-warning" type="button" ng-click="$close()">Cancel</button>
</div>
我建議設置[筆](http://codepen.io/)/ [小提琴](https://jsfiddle.net/) /[plunker](https://plnkr.co/edit/?p=catalogue)。 – alphapilgrim
我可以嘗試,但我所能做的只是這個,它與上面描述的代碼沒有相同的功能.....其實它根本不工作,我不知道爲什麼..... 。(第一次在蹦極)..... https://plnkr.co/edit/aSQsetlSuKlxYNpHMxCf?p=preview – newbie