具有反向操作的 Angular 清单模型复选框 [英] Angular checklist-model checkboxes with reverse action

查看:49
本文介绍了具有反向操作的 Angular 清单模型复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用

解决方案

更新了我的演示 有问题所以看看最终结果

I'm working with checklist-model.js for angular to select from dynamically generated list of objects. It's working fine, but now I need to make it work in reverse so when I uncheck any of checkbox - place it to new array (and when checked back - remove from array). Can any of You give me some ideas or tell me next steps how to deal with it?

html:

<label>
    <input type="checkbox"
        ng-model="check_all_domains"
        ng-click="toggle_select_all()"/> all
</label>
<label ng-repeat="objects in objects_model">
    <input type="checkbox"
        checklist-model="objects_selected"
        checklist-value="objects"
        ng-checked="check_all_domains"/>
    {{objects.name}}
</label>

model:

$scope.objects_model = [
    {id : '1', name: 'name1'},
    {id : '2', name: 'name2'},
    {id : '3', name: 'name3'},
  ];
$scope.objects_selected = [];
$scope.check_all_domains = false;

$scope.toggle_select_all = function() {
    $scope.objects_selected = [];
};

here is screenshot how it's working right now:

and here is how I want it to work:

UPDATED: WORKING AS IT SHOULD DEMO

解决方案

Updated my demo in question so have a look at the final result

<label ng-repeat="objects in objects_model" class="test">
    <input type="checkbox" 
          checklist-model="objects_selected" 
          checklist-value="objects" />
    <i ng-class="{checked : check_all_domains, 
                unchecked : !check_all_domains, 
                fakecheck : check_all_domains}"></i>{{objects.name}}
  </label>

这篇关于具有反向操作的 Angular 清单模型复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆