user3703527 user3703527 - 1 month ago 13
AngularJS Question

how to make dynamic form in angular?

I am trying to make form in angular.I got little bit success in that .Actually I make form using json .When i take single json file it is essay because I write my html of form and display it and using iteration I display the form.Now if I have 3 or 4 json file I need to get generate different form with different ids and display it .can I make generate dynamic forms?

I take two button which get json data from file "A" and "B".I need to show diferent form on different button click

plunker
http://plnkr.co/edit/OqlTmddgAGRkcXSKtJNT?p=preview

$scope.getFromAFile= function () {
// body...
var inputs=[];
$http.get('a.json').success (function(data){
$scope.formInputs = data.input
angular.forEach($scope.formInputs, function(value, key) {
/* do something for all key: value pairs */
inputs.push({"value":value.value,"inputValues":value.inputValues,"type":value.inputType.toLowerCase(),"name":value.name,"required": value.required})
});
getFormfromData(inputs,'BID')
}).error(function(err){
alert(err);
});

}

$scope.getFromBFile= function () {

// body...
$http.get('b.json').success (function(data){
var inputs=[];

$scope.formInputs = data.input
angular.forEach($scope.formInputs, function(value, key) {
/* do something for all key: value pairs */

inputs.push({"value":value.value,"inputValues":value.inputValues,"type":value.inputType.toLowerCase(),"name":value.name,"required": value.required})
});
getFormfromData(inputs,'BID')
}).error(function(err){
alert(err);
});

}

Answer

There are good "librairies" to build forms from JSON. To name only 2 of them: