In AngularJS, a Controller gets the data from the View, processes it, and then delivers it to the view that is displayed to the end user. Your fundamental business logic will be stored in the Controller. The controller will use the data model to perform the necessary processing before passing the output to the view, which will then display it to the end user.
Using the ng-controller directive, we declare a controller named studentController. This is how we define it:
The $scope variable refers to the application that makes use of the studentController object.
The studentController object has a property called $scope.student.
The $scope.student object has two properties: firstName and lastName. We give them the default values.
The combined name is returned via the fullName field of the $scope.student object.
We acquire the student object and then return the combined name in the fullName function.
Note that the controller object can also be defined in a separate JS file and referenced from the HTML page.
We can now use the student property of the studentController with ng-model or expressions as follows:
We binded the student. two input boxes: firstName and student.lastname
HTML was connected to student.fullName().
Now, whenever you type something in the first and last name input boxes, the whole name is immediately updated.
The use of controller is demonstrated in the following example.
Angular is a fantastic multi-functional framework that helps you develop faster. It is a strong software development environment that includes dependency injection and deep linking.