すべてのチェックボックスをオンにしたい場合は、次のように試してみてください。 HTML: <ion-checkbox class="card" ng-repeat="(key, value) in packages" ng-model="value.checked" ng-checked="value.checked" ng-change="add(packages)"> <div class="title">{{value.title}}</div> <div class="price-section">{{value.price}}</div> </ion-checkbox>
コントローラ: $scope.add = function(item) { $scope.boxes = []; //push the boxes onto boxes that you want to be selected. $scope.value.checked = $scope.boxes }
あなたの例を使って説明するのは難しいです。このようなことをやっている場所のコードを見せてください。私はユーザー名のリストを持っています。ユーザーがchangedDepartment関数を呼び出すと、ドロップダウン内のすべてのユーザーを選択するかどうかを尋ねます。
HTML:
<select ng-model="selectDept" ng-change="changedDepartment(selectDept)" ng-options="option as option.departmentName for option in department" multiple="multiple">
<option value="" disabled>Select a Department/s</option>
</select>
コントローラ:
$scope.changedDepartment = function(item) {
\t $scope.users = [];
\t $scope.selectUser = [];
\t if ($scope.department.length > 0) {
\t if (item[0].DepartmentUsers.length > 0) {
\t \t $scope.users.length = 0;
\t \t for (var i = 0; i < item.length; i++) {
\t \t for (var j = 0; j < item[i].DepartmentUsers.length; j++) {
\t \t if (profile[0].userProfileID != item[i].DepartmentUsers[j].userProfileID) {
\t \t console.log(item[i].DepartmentUsers[j]);
\t \t $scope.users.push(item[i].DepartmentUsers[j]);
\t \t }
\t \t }
\t \t }
\t \t var confirm = $ionicPopup.confirm({
\t \t title: 'Confirm',
\t \t template: 'Would you like to send to all the users in ' + item[0].departmentName + ' department?',
\t \t cancelText: 'No',
\t \t okText: 'Yes'
\t \t });
\t \t confirm.then(function(res) {
\t \t if (res) {
\t \t $scope.selectUser = $scope.users;
\t \t } else {
\t \t $scope.selectUser = [];
\t \t }
\t \t });
\t \t //item.pop();
\t \t //$scope.changedDepartment(item);
\t \t }
\t \t item = "";
\t \t }
\t }
ループの巨大を無視します。それは、ユーザーのために自分のデータモデルを検索し、$ scope.usersにプッシュすることだけです。主な焦点は、すべてのユーザーを選択するかどうか尋ねられたときです。これはループの前にプッシュしたユーザーのアレイ全体にng-modelを設定します。
チェックボックスを使用していて、複数の選択肢のドロップダウンを使用していたため、これがあなたの状況に関連するのかどうかわかりませんが、うまくいけばそれが役立ちます。
これを解決するためにサンプルコードが必要です – yunandtidus
タイトルを見ることができるようにjsコードを少し投稿してください –