Hi guys. I am very new in JS. I wan’t to have at least one input form and it can have more forms like that by adding button. In addition, i don’t know how to use ng-model to store all input value like that. I’m not sure you guys can understand my problem :D. So for more information, please leave comment. Tks you.
I haven’t used Angular for some time (and haven’t used Angular 2 at all) but I’ll see if I can help.
So you want a form that can have input elements added to it, each of which you want to use ng-model to store the values of?
I think you would have your input elements in an ng-repeat loop, rendering each input element for an array that contains the name that will be used in ng-model.
In the example code, they have an object
newObject where the values of each element is stored, and they have an array
items (both in their
$scope) that holds the names for each element.
They use ng-repeat to loop through their items array, and give each checkbox’s ng-model a value of
newObject[item.name]. This will set their ng-model to the value of each property of
newObject with the name coming from the
I feel like I might not have explained that very well, so let me know if I didn’t. I hope that was what you’re trying to do, if not let me know!
thanks for your help. But I mean that I have one input form by default and I also have an ADD button( when user click on it, another input form will appear) All of input maybe be stored in an array.
I know it’s basic, but is this demo what you’re going for?
The button adds a new input element, and its value is accessible through the $scope.
Thanks you very much bro. It helps me a lots