Help us understand the problem. What is going on with this article?

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

More than 3 years have passed since last update.

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

http://vitalets.github.io/checklist-model/

使い方

モジュール「"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>
sugasaki
個人的なメモが多いです。 書いてる事は個人の見解であり所属する組織の公式見解ではありません
https://sugasaki.com/
runners
スポーツで世界を良くしたいエンジニアチーム。応援navi、.finisher、run&といった製品開発をしています!
https://www.wantedly.com/projects/167082
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした