I want the radio button to be selected depending on the given JSON format.
{
"autoselect": [
"fugiat"
],
"component": "radio",
"description": "necessitatibus accusantium aliquid iste non",
"editable": false,
"label": "in sunt",
"options": [
"fugiat",
"commodo hic",
"exercitationem"
],
"required": true
},
{
"component": "radio",
"description": "necessitatibus accusantium aliquid iste non",
"editable": false,
"label": "in sunt",
"options": [
"fugiat",
"commodo hic",
"exercitationem"
],
"required": true
}
Radio button should display on the basis of number of element in options array.
And the value of radio button based on autoselectvalue. If autoselectvalue match with any value of options then corresponding option radio button will be true and remaining will false.
And if JSON object does not contain autoselect value then none of the radio buttons should be selected initially.
HTML code
<div data-ng-if="formData.component=='radio'" class="form-group">
<label class="col-sm-2 control-label">{{formData.label}} : </label><br>
<div class="col-sm-8">
<div class="row" data-ng-repeat="option in formData.options"
data-ng-disabled="{{!formData.editable}}"
data-ng-required="{{formData.required}}">
<label class="col-sm-4">{{option}} : </label>
<div data-ng-if="formData.hasOwnProperty('autoselect')" data-ng-repeat="autoselect in formData.autoselect">
<div data-ng-if="option === autoselect">
<input class="col-sm-1" type="{{formData.component}}" data-ng-model="radioAction.checked">
</div>
<div data-ng-if="option !== autoselect">
<input class="col-sm-1" type="{{formData.component}}" data-ng-model="!radioAction.checked">
</div>
</div>
<div data-ng-if="!formData.hasOwnProperty('autoselect')">
<input class="col-sm-1" type="{{formData.component}}" data-ng-model="radioAction">
</div>
</div>
</div>
</div>
Contoller.js
$http.get("data.json")
.then(function(response){
$scope.formDatas = response.data.data;
console.log($scope.formDatas);
//$scope.autoSelect = $scope.formDatas.form_fields.autoselect[0];
});
when autoselect values is not there that time my code is not working.
Kindly help me in particular scenario. code is here: plunker
Thanks in advance..