Below is my array :
$scope.parent.cars1 = ["Saab", "BMW"]; // There are more than 1000 records in this array
$scope.child.Cars1 = [];
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 array i.e name, operation and selected and by default operation property will be 1 and selected property 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 as my records $scope.parent.Cars1 contains thousands of records, so my browser gets hang because I am using this $scope.child.Cars1 on my view to display records like 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 given below, so that browser doesn't get hanged because of huge number of records:
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
});
});
Using @Bear plunker this happens:
