Very new to angularjs, so please forgive me if it is easy one.
I want to create dynamic rows for input fields, using angularjs's ng-repeat . basically i have a question object, and i want to add options to that question, by default user will have 2 rows for option, but he/she can add more options to question buy adding another row.
<div nd-repeat="option in question.options">
<label>{{$index+1}}</label>
<input type="text" ng-model="option.number" ng-change="change()" />
<input type="text" ng-model="option.description" ng-change="change()" />
<br/>
</div>
basically i am facing 2 problems:
How should I add the new row having 2 inputs(empty) with ng-model, and read that ng-model back in controller? I do not want to new option with any empty fields, i want to have option object get added in array, and when user edits those input fields, the values should get updated in controller through ng-model
How to form the question object so i can send it to server where question object has a property as array of options (the auto-mapping should work)
here are my models at server side for question and option..
public class Option
{
public int Number { get; set; }
public string Description { get; set; }
}
public class Question
{
public int Id { get; set; }
//....opther properties
public Option[] Options { get; set; }
}