How to define angularjs controller with example

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

Recommended Posts:


Prem Tiwari

An engineer by profession and a passionate blogger by heart. Founder of FreeWebMentor.com (A Programming blog for beginners), Tech Speaker at various forums. A part from this he is an open source enthusiast, WordPress Lover, Blogger, SEO, and Growth Strategic.

Article 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.

Solved Programs