1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

AngularJS Checkbox群から選択したものを取得

Last updated at Posted at 2016-02-17

AngularJSで、Checkbox群の中から選択したものだけを保持するオブジェクトを提供する。

使い方

モジュール「"checklist-model"」を読み込む

js

var app = angular.module("app", ["checklist-model"]);
app.controller('Ctrl1', function($scope) {

//Checkbox表示用リストの作成
  $scope.roles = [
    'guest', 
    'user', 
    'customer', 
    'admin'
  ];
  
  //状態保存用オブジェクト作成
  $scope.user = {
    roles: ['user']
  };
 
});


html


<label ng-repeat="role in roles">
  <input type="checkbox" checklist-model="user.roles" checklist-value="role"> {{role}}
</label>



選択項目の確認用リスト表示
<div class="col-lg-2">
    <ul class="list-group">
        <li class="list-group-item" ng-repeat="item in user.roles">{{item.Text}}</li>
    </ul>
</div>

拡張

Jsonをそのまま格納も可能
その際にはchecklist-value → data-checklist-valueに変更する

<label ng-repeat="role in roles">
  <input type="checkbox" checklist-model="user.roles" checklist-value="role"> {{role}}
</label>
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?