In AngularJS I am trying to make different editable forms from JSON data. I am getting JSON data from $http
call.
Sample json data.
{
{"NodeType": "User","NodeDetail":{"Name": "Sam", "Age":24,"Gender":"Male"} },
{"NodeType": "User","NodeDetail":{"Name": "Dazy", "Age":22,"Gender":"Female"} },
{"NodeType": "Occupation","NodeDetail":{"Type": "Contract","Traveling":"Yes","Benifits":"No", "Medical":"Annual"} },
{"NodeType": "City","NodeDetail":{"Name": "London","Area":"1,572 sq-km","Elevation":"35 m","Population":"87.9 lakhs"} }
}
I am able to achieve in my HTML as below,
Based on the NodeType the form will have input, text area, radio button etc. As below image,
I think I can do by putting form in ng-if
directive. But the problem is , there will be around 40-50 NodeTypes so having all form templates in ng-if will make the page very lengthy. I would prefer to have form template in a external .js file and load from there based on NodeType. Is it possible ? I please guide me what will be the best approach to achieve this. Pointer to any working demo/example will be great help.
Thanks & regards