How to define angularjs controller with example

| Last Updated: | In: Angular JS

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.


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

About: Prem Tiwari

Prem Tiwari is the founder of and is a professional developer who has vast experience in PHP and open source technologies. Apart from this, he is a blogger by hobby.

You may also like:

, , , , , , ,