Search code examples
angularjsangular-ngmodel

fetching data from a dynamic form in angular js


I've got a json file that generates the form definitions for each specific form. In the view - I spit out the data something like this

<input ng-data-model="data[value2.Id]" placeholder="{{value2.Label}}" type="text" />

<button ng-click="send_form()" >Submit</button>

In my controller, I've got the following function

$scope.send_form = function() {
    alert($scope.data);
}

When the send_form function is called - i get "undefined" returned back. My question is, how do i handle dynamic form data in Angular JS and get each of the values inserted by the user? Is there a way to get a key/value pair set of data returned? with the ng-data-model has the key and the value inserted by the user as a user? Or how would i handle this specific scenario? Any help would do :)

Thanks :)


Solution

  • It's just ng-model to bind your input to your scope variable. Or you can use data-ng-model for compliance. Other than that it should work if your data is set up - might help to show an example of how it looks.

    Here's a fiddle with some dummy data: https://jsfiddle.net/ba0pj6sv/