AngularJS Controller Properties Examples




AngularJS Controller Properties

<!DOCTYPE html>
<html>
   <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js">
   </script>
   <body>
      <div ng-app="myApp" ng-controller="personCtrl">
         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('personCtrl', function($scope) {
            $scope.firstName = "Ali";
            $scope.lastName = "Khan";
            $scope.fullName = function() {
               return $scope.firstName + " " + $scope.lastName;
            };
         });
      </script>
   </body>
</html>

Output