How do I bind to list of checkbox values with AngularJS?

前端 未结 29 2326
天涯浪人
天涯浪人 2020-11-22 05:20

I have a few checkboxes:





        
29条回答
  •  误落风尘
    2020-11-22 06:04

    I've put an array in the controller.

    $scope.statuses = [{ name: 'Shutdown - Reassessment Required' },
        { name: 'Under Construction' },
        { name: 'Administrative Cancellation' },
        { name: 'Initial' },
        { name: 'Shutdown - Temporary' },
        { name: 'Decommissioned' },
        { name: 'Active' },
        { name: 'SO Shutdown' }]
    

    On the markup I've put something like following

    {{status.name}}
    {{$scope.checkboxes}}

    The output was the following, in the controller I just needed to check whether its true or false; true for checked, absent/false for unchecked.

    {
    "Administrative Cancellation":true,
    "Under Construction":true,
    "Shutdown - Reassessment Required":true,
    "Decommissioned":true,
    "Active":true
    }
    

    Hope this helps.

提交回复
热议问题