SO - 35601299

HTML

<div ng-controller="MyCtrl">
  <button ng-click="checkSelectedphones()">
    Check selected phones
  </button>

  <div ng-repeat="phone in phones | unique:'brandname'">
    <label>
      <input type="checkbox" ng-true-value="'{{phone.brandname}}'" ng-false-value="''" ng-model="selectedBrands[$index]" ng-change="selectBrand(phone)"> {{phone.brandname}}
    </label>
  </div>

  <br>

  <div ng-repeat="brand in selectedBrands track by $index" ng-if="brand">
    {{brand}}
    <div ng-repeat="phone in phones" ng-if="phone.brandname === brand">
      <label>
        <input type="checkbox" ng-model="phone.selected"> {{phone.modelname}}

      </label>
    </div>
  </div>
</div>

JavaScript

var myApp = angular.module('myApp', []);

myApp.controller('MyCtrl', function($scope, $http) {
  $scope.selectedBrands = [];

  $scope.selectBrand = function(selectedphone) {
    // If we deselect the brand
    if ($scope.selectedBrands.indexOf(selectedphone.brandname) === -1) {
      // Deselect all phones of that brand
      angular.forEach($scope.phones, function(phone) {
        if (phone.brandname === selectedphone.brandname) {
          phone.selected = false;
        }
      });
    }
  }

  $scope.checkSelectedphones = function() {
    var modelNames = [];
    var jsonArr = [];
    var subModelArr = [];
    var aletrMsg = '';
    angular.forEach($scope.phones, function(phone) {
      if (phone.selected) {
        modelNames.push(phone);
        var found = jsonArr.some(function(el) {
          if (el.model === phone.brandname) {
            el.subModel.push(phone.modelname);
            return true;
          }
        });

        if (!found) {
          subModelArr.push(phone.modelname);
          jsonArr.push({
            model: phone.brandname,
            brand: 'Nokia',
            subModel: subModelArr,
            city: 'Noida',

          });
          subModelArr = [];
        }

      }

      phone.selected = false;
    });
    console.log(modelNames.length);
    if (modelNames.length == 0) {
      alert(modelNames.length ? aletrMsg : 'No phones selected!');
    } else {
      console.log(jsonArr);
    }

    $scope.selectedBrands = [];
  }

  $scope.phones = [{
    id: "986745",
    brandname: "Nokia",
    modelname: "Lumia 735 TS"
  }, {
    id: "896785",
    brandname: "Nokia",
    modelname: "Nokia Asha 230"
  }, {
    id: "546785",
    brandname: "Nokia",
    modelname: "Lumia 510"
  }, {
    id: "144745",
    brandname: "Samsung",
    modelname: "Galaxy Trend 840"
  }, {
    id: "986980",
    brandname: "Samsung",
    modelname: "Galaxy A5"
  }, {
    id: "586980",
    brandname: "Samsung",
    modelname: "Galaxy Note 4 Duos"
  }, {
   ...