Thursday, February 18, 2016

AngularJS Controllers (ng-controller)

It controls the application data. It is a regular javascript object created by object constructor.
It wraps up all logic for UI manipulation and is a bridge between client side and server side/third party API's etc.

It stores the application data and performs operations on it depending on requirements.

<div ng-app="myApp" ng-controller="myController">
First Name: <input type="text" ng-model="firstName"><br>
Last Name: <input type="text" ng-model="lastName"><br>
<br>
Full Name: {{fullName()}}
</div>

<script>
var app = angular.module('myApp', []);
app.controller('myController', function($scope) {
    $scope.firstName = "";
    $scope.lastName = "";
    $scope.fullName = function() {
        return $scope.firstName + " " + $scope.lastName;
    };
});
</script>

No comments:

Post a Comment