How do I add new text box when submit button is pushed. This is what I have tried and I know there's some thing wrong. I am still new to angular js.
Example:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Example - example-ngController-production</title>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.4.0/angular.min.js"></script>
<script>
angular.module('controllerAsExample', []).controller('SettingsController1', function ($scope) {
$scope.contacts=[]
$scope.addContact = function()
{
$scope.contact.push({$scope.contact})
}
});
};
</script>
</head>
<body ng-app="controllerAsExample">
<div id="ctrl-as-exmpl" ng-controller="SettingsController1">
<ul>
<li ng-repeat="contact in contacts">
<input type="text" ng-model="contact" />
</li>
<li><button ng-submit="addContact()">add</button></li>
</ul>
</div>
</body>
</html>
In you code, you are doing:-
This is where the problem is. If you just need to add an empty textbox, you just need to add an empty contact to contacts, and ng-repeat will take care of adding the new textbox in the list. Another thing is that you were pushing into contact, and not contacts.
Also, ngSubmit is used inside a form, which you do not have. So, use ng-click instead. Here is a plunker showing the code working.