The processes of submitting information on a web page are normally handled by the submit event on the web browser. This event is normally used to send information which the user might have entered on a web page to the server for further processing.
AngularJS also provides a directive called ng-submit which can be used to bind the application to the submit event of the browser.
So in the case of AngularJS, on the submit event you can carry out some processing within the controller itself and then display the processed information to the user.
Let's take an example of how we can achieve this.
In our example,
We are going to present a textbox to the user in which they can enter the topic which they want to learn. There will be a submit button on the page, which when pressed will add the topic to an unordered list.
<!DOCTYPE html> <html> <head> <meta chrset="UTF 8"> <title>Event Registration</title> </head> <body ng-app="sampleApp"> <script src="https://code.angularjs.org/1.6.9/angular-route.js"></script> <script src="https://code.angularjs.org/1.6.9/angular.min.js"></script> <script src="https://code.angularjs.org/1.6.9/angular.js"></script> <script src="/lib/bootstrap.js"></script> <script src="/lib/bootstrap.css"></script> <h1> Guru99 Global Event</h1> <div ng-controller="AngularController"> <form ng-submit="Display()"> Enter which topic you would like to learn <input type="text" ng-app="sampleApp" ng-model="Topic"><br> <input type="submit" value="Submit"/> <ul ng-repeat="topicname in AllTopic"> <li>{{topicname}}</li> </ul> </form> </div> <script> var app = angular.module("sampleApp",[]); app.controller("AngularController",function($scope) { $scope.Display = function () { $scope.AllTopic.push($scope.Topic); } }); </script> </body> </html>
Code Explanation:
If the code is executed successfully, the following Output will be shown when you run your code in the browser.
Output:
To see the code working, first, enter a Topic name like "AngularJS" as shown above in the textbox and then click on the Submit button.
Summary
The "ng-submit" directive is used to process the input entered by the user when the form is submitted