How to define angularjs controller with example

Prem Tiwari - - 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 also a professional developer who has vast experience in PHP and open source technologies. Apart from this, he is a blogger by hobby and also he has been a regular speaker of WordPress sessions in various IT Companies.

Tags: , , , , , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.