How to create a dynamic form in the angular, this form is composed of categories and types. It was supposed to create a tab
with the various categories and within each category show the types.
Below is the code example.
<div class="row">
<div class="col-xs-12">
<div class="box box-primary">
<div class="box-body" id="teste" ng-app="app" ng-init="chargeData()" ng-controller="FormCtrl">
<ul class="nav nav-tabs" role="tablist">
<li ng-repeat="category in categories"><a href="#{{category.ClinicalExamCategoryId}}" data-toggle="tab">{{category.clinicalExamCategoryName}}</a></li>
</ul>
<div class="tab-content">
<div class="tab-pane active" ng-repeat="category2 in categories2" id="{{category2.ClinicalExamCategoryId}}">
<br>
<div id="{{category2.ClinicalExamCategoryId}}" class="row" ng-init="chargeType(category2.ClinicalExamCategoryId);">
<div ng-repeat="type in types " id="{{category2.ClinicalExamCategoryId}}" class="col-xs-6">
<div id="{{type.ClinicalExamTypeId}}" class="box box-primary">
<div class="box-header">
<h3 class="box-title" id="{{type.clinicalExamTypeName}}">{{type.clinicalExamTypeName}}</h3>
<div class="box-body">
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
Controller:
$scope.chargeData = function () {
$http.get("/ClinicalExams/SelectCategory").success(function (data, status, headers, config) {
$scope.categories = data;
$scope.categories2 = data;
// chargeType(id);
}).error(function (data, status, headers, config) {
$scope.state = "ERRO DE EXECUÇÃO";
});
}
$scope.chargeType = function (id) {
$http.get("/ClinicalExams/SelectType/"+id).success(function (data, status, headers, config) {
$scope.types = data;
}).error(function (data, status, headers, config) {
$scope.state = "ERRO DE EXECUÇÃO";
});
}