AngularJS Controller

Posted by Sumeet Arora
6
Jul 22, 2015
510 Views
Image

AngularJS applications are controlled by controllers. A controller is a JavaScript Object, which is created by a standard JavaScript object called constructor. In below example lastName and firstName are two properties of controller object demonstrated below.

  1. <div ng-app="myApp" ng-controller="myCtrl">
  2. First Name: <input type="text" ng-model="firstName"><br>
  3. Last Name: <input type="text" ng-model="lastName"><br>
  4. <br>
  5. Full Name: {{firstName + " " + lastName}}
  6. div>
  7. <script>
  8. var app = angular.module('myApp', []);
  9. app.controller('myCtrl', function($scope) {
  10.     $scope.firstName = "Raj";
  11.     $scope.lastName = "shekhar";
  12. });
  13. script>

Reference

http://www.w3schools.com/angular/angular_controllers.asp

To read such more blogs on AngularJS please visit our AngularJS Blogs Section.

Comments
avatar
Please sign in to add comment.