Javascript AngularJS表单如何显示单选按钮和json中的数据
我无法正确显示json数据Javascript AngularJS表单如何显示单选按钮和json中的数据,javascript,angularjs,json,Javascript,Angularjs,Json,我无法正确显示json数据 如何显示我的json文件()中的单选按钮 此外,我希望在提交时验证该表格 html: {{field.label} 验证 提交 以下是您可以反复查看收音机选项的方法。我同意@charlietfl的观点,你应该使用一个像这样的角形库 {{field.label} {{option.label} {{field.label} 首先在控制器上启动一个值 $scope.richestClub = {}; $http.get('form
- 如何显示我的json文件()中的单选按钮
- 此外,我希望在提交时验证该表格
{{field.label}
验证
提交
以下是您可以反复查看收音机选项的方法。我同意@charlietfl的观点,你应该使用一个像这样的角形库
{{field.label}
{{option.label}
{{field.label}
首先在控制器上启动一个值
$scope.richestClub = {};
$http.get('form.json').success(function(response) {
$scope.result = response;
var fields = response.fields;
$scope.richestClub.val = fields.answer.options[0].value;
console.log($scope.richestClub);
console.log($scope.fields);
});
Html:
{{field.label}
{{option.label}
验证
提交
使用动态表单模块,如angular formly,而不是重新发明Wheels谢谢,俄勒冈州,是否也可以在提交时验证表单?请就此单独提问。如果您使用formly,那么如何进行验证将是显而易见的。嗨,Korte,谢谢您的关注。请检查这是这样的吗?是的,请看我编辑的答案。您还应该在读取json文件之后启动该值<代码>$scope.richestClub=字段。答案。选项[0]。值代码>。(不要这样更改ng model='richestClub'
)?它应该做些什么吗?我需要将表单提交给另一个模拟API端点,该端点根据提供的答案是否正确返回true或false,并在UI中显示此响应!!不知道怎么做!那么你应该看看这里:
<fieldset>
<div ng-repeat="field in result.fields">
<div ng-if="field.type === 'radio'">
<span>{{field.label}}</span>
<div ng-repeat="option in field.options">
<label for="{{option.label}}">{{option.label}}</label>
<input ng-required="{{field.required}}"
value="{{options.value}}"
id="{{options.label}}"
type="{{field.type}}" >
</div>
</div>
<div ng-if="field.type !== 'radio'">
<label for="{{field.type}}">{{field.label}}</label>
<input ng-required="{{field.required}}"
value="{{options.value}}"
type="{{field.type}}" >
</div>
<form-error ng-show="{{field.errorMessages.required}}"></form-error>
<form-error ng-show="{{field.errorMessages.invalid}}"></form-error>
</div>
</fieldset>
$scope.richestClub = {};
$http.get('form.json').success(function(response) {
$scope.result = response;
var fields = response.fields;
$scope.richestClub.val = fields.answer.options[0].value;
console.log($scope.richestClub);
console.log($scope.fields);
});
<form ng-submit="submitForm()" novalidate>
<fieldset>
<div ng-repeat="field in result.fields">
<label for="{{field.type}}">{{field.label}}</label>
<input ng-if="field.type != 'radio'" ng-required="{{field.required}}" value="{{options.value}}" type="{{field.type}}">
<div ng-if="field.type == 'radio'">
<div ng-repeat="option in field.options">
<input type="{{field.type}}" ng-model="richestClub.val" value="{{option.value}}">{{option.label}}</br>
</div>
</div>
<form-error ng-show="{{field.errorMessages.required}}"></form-error>
<form-error ng-show="{{field.errorMessages.invalid}}"></form-error>
</div>
</fieldset>
<button type="button" ng-click="onValidate(); return false;"> Validate</button>
<button type="submit" ng-disabled="userForm.$invalid"> Submit </button>
</form>