Below is my array:
$scope.parent.cars1 = ["Saab", "BMW"];
Now I am trying to assign $scope.parent.cars1 to $scope.child.Cars1 , but would like to have 3 properties in my $scope.child.Cars1 , i.e. the name, operation, and the selected , and by default, the operation property will be 1 and selected will be true.
Code:
$scope.child = {}; if ($scope.child.Cars1 == undefined) $scope.child.Cars1 = []; angular.forEach($scope.parent.Cars1, function(obj, key) { $scope.child.Cars1.push({ name: obj, operation: 1, // this value is used to tick all radio button of clear and save selected: true // this value is used to check all checkbox to true by default }); })
Now that my $scope.parent.cars1 contain thousands of entries, my browser freezes because I use this $scope.child.Cars1 in my view to display the entries, as shown below:
<tr ng-repeat="item in child.Cars1 | myfilter : searchitem"> <td> <input ng-model="item.selected" type="checkbox" name="a{{$index}}" id="a{{$index}}"> </td> <td> <div> <input type="radio" ng-model="item.operation" value="0" name="b{{$index }}" id="b{{$index}}">Clear </div> <div> <input type="radio" ng-model="item.operation" value="1" name="b{{$index }}" id="b{{$index}}">Clear and Save </div> </td> </tr>;
Update: I am trying to avoid the process described below so that the browser cannot hang itself due to the huge number of entries:
angular.forEach($scope.parent.Cars1, function(obj, key) { $scope.child.Cars1.push({ name: obj, operation: 1, // this value is used to tick all radio button to true by default selected: true // this value is used to check all checkbox to true by default }); });
Plunker
Using @Bear plunker, this happens:
