JSFiddle - React, Tailwind, and code Playground

by michaeldeongreen

HTML

<div ng-app>
    <div ng-controller="jsFiddleController">
        <input type="text" name="firstName" value="{{firstName}}">
            <div ng-repeat="company in companies">
                <input type="checkbox" name="group" ng-model="selectedCompanies[company.name]">{{company.name}}
            </div>
                <div>
                    {{selectedCompanies | json}}
                </div>
                <div>
                    {{dto.companies | json}}
                </div>
                <div>
                    <input type="button" value="submit" ng-click="test()">
                </div>
    </div>
</div>

JavaScript

function jsFiddleController($scope){
    
    $scope.companies = [{name: '1'}, {name: '2'}, {name: '3'}];
    
    $scope.selectedCompanies = {};
    
    $scope.firstName = 'Michael Green';
    
    $scope.dto = {
        companies: []
    };
    
    $scope.test = function () {
        $scope.dto.companies = [];
        angular.forEach($scope.selectedCompanies, function (value, key) {
            if (value == true) {
                $scope.dto.companies.push({id: key, name: ''})
            }
        });
    }
    
}