AngularJs controller example

The AngularJs controller is an object that is created by using JavaScript constructor.

The controller is handling the DOM elements with the help of using ng-controller directive and angular scope.

What Is Scope?  The scope is an object that works between the controller and DOM and proved the link between the controller and view.

The controller are used to initialize the $scope objects and add the $scope behavior also.

The controller are contains the business logic only and not used for DOM manipulation.

The Syntax of controller

var app = angular.module('angularApp', []);
app.controller('angularCtrl', function ($scope) { });

The full live Example code as given below
<!DOCTYPE html>
    <script src=""></script>
    <script type="text/javascript">
        var app = angular.module('angularApp', []);
        app.controller('angularCtrl', function ($scope) {
            $scope.FName = "Anil";
            $scope.LName = "Singh";

<body ng-app="angularApp">
    <div ng-controller="angularCtrl">
        First Name:    <input type="text" ng-model="FName"><br />
        Last Name:    <input type="text" ng-model="LName">
        <br />Full Name: {{FName + " " + LName}}

The Output

About Blogger


Hey! I am Anil Singh. I am Active Blogger, Writer and Programmer. I love learning new technologies, programming, blogging and participating the forum discussions more...

    Blogger Comment
    Facebook Comment
SQL Server NodeJs TypeScript JavaScript Angular SQL Server My Book