Gayan
Gayan

Reputation: 2860

radio box selected item on angularjs

i'm wonder how could i set up selected item checked when i'm using radio button list

my sample code look like this

<div ng-repeat="vehicle in filteredVehicle">
<input type="radio" name="radiog_lite" id="radio_{{$index}}" class="css-checkbox" ng-value="vehicle" ng-model="$parent.selectedVehicle" ng-disabled="vehicle.enable == '0'" />
<label for="radio_{{$index}}" class="css-label radGroup1" ng-if="vehicle.enable == '1'"></label>
<h5>{{vehicle.vehicleTypeName}}</h5>

below i have created plunker please help me to fix the selected item selected vehicle is on $scope.selectedVehicle

Plunkr

Thanks

Upvotes: 0

Views: 40

Answers (1)

Satpal
Satpal

Reputation: 133403

You should bind the selectedVehicle with the object with in the array. The reason behind it is that angular add $$hashKey to every object.

Use

$scope.selectedVehicle = {};
$scope.filteredVehicle = {};

$http.get('data.json').then(function(d){
    angular.forEach(d.data.vehicleType, function(value, key) {
          if(value.vehicleTypeID ==  d.data.selected.vehicleTypeID){
            $scope.selectedVehicle = value;
          }
    });
    $scope.filteredVehicle = d.data.vehicleType;
});

DEMO

Upvotes: 2

Related Questions