I'm using Angular JS to work on a proof of concept for a SPA that needs to be able to handle dynamic form generation. This project is essentially an interview style application that will have a user go through multiple screens to answer questions to be rated against the server. I'm trying to write a generic controller that can handle any interview page, which gets the actual page content from a server call (the view is obviously going to be page specific). I can handle the page content fairly easily by just wrapping my returned data in a containing variable so that my view just has to access that root variable and path down using JSON
Example (pageData being the generic container variable):
ng-model="pageData['AccountInput.Address1'].value"
The problem arises when I want to integrate something a little more involved than just simple data output - something like the ngTable directive to implement pagination or sorting to a standard table. The logic for this is supposed to be contained within the controller. So my question is whether it's possible to make my controller generic enough that I can look at my JSON response and create one or more pieces of dynamic code in my controller to create something along the lines of this ngTable? Basically, check for any arrays in my response that has a properties object that can be used as the settings for the table and have the controller iterate through all of the JSON to find these.
For reference, here's the code required for the ngTable in the controller as per the links above.
$scope.tableParams = new ngTableParams({
page: 1, // show first page
total: data.length, // length of data
count: 10 // count per page
});
question
element, is able to output the appropriate element, be it aninput
, atextarea
, or angTable
. – frapontillo Oct 9 '13 at 18:52