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.

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

Tags: , , , , , , ,


About: Prem Tiwari

Prem Tiwari is the founder of freewebmentor.com 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:

Follow us!

Get Free Access of 400+ Scripts

Don't worry you'll not be spammed!

Featured eBook

WordPress Security Guide

Free Guide: Learn how to implement security guideline in your WordPress site...

DOWNLOAD

Pincode Finder

pincode-finder tool

Online Pincode Finder

Best tool to locate post Office address and pincodes of all india...

SEARCH NOW