In today’s tutorials i will explain how to define angularjs controllers. This tutorial will help you to create the controllers in your angularjs applications.

What is controller in AngularJS?

Angularjs controllers are regular JavaScript objects which control the data in your angularjs applications. ng-controller directive defines in your application controller.

angularjs-controller

Below is the example of angularjs controller. In the below example I have created a testController.

You can testController in your HTML file like below:

Below is the complete example of angularjs controllers. Copy paste below code and create a index.html file to test angularjs controlller. The below example demonstrate a controller object with two properties: firstName and lastName.

Live demo

You may also like: