Angularjs in Hindi Controller




AngularJS Controllers AngularJS Applications के Data को नियंत्रित करता है. एक Controller AngularJS Application का सबसे उपयोगी हिस्सा होता है. यह Javascript Functions के बहुसंख्यक संबंधित और UI संबंधित कार्य करता है.

Application मे Data के Flow को नियंत्रित करने के लिए AngularJS Controller को Ng-Controller Instructions के साथ परिभाषित किया गया है. AngularJS Controller एक Javascript Object होता है जिसमे Attributes और Function शामिल होते है.

सभी प्रकार की Website को Angularjs Controller से Add करने के लिए Ng-Controller Directive का उपयोग किया जाता है. AngularJs के उपयोग से बनने वाली Website की सबसे अच्छी बात यह होती है यह Angularjs Controller पर आधारित होती है.

For Example

<!DOCTYPE html>
<html>
   <head>
      <title>Angular JS Controller Example</title>
      <script src = 
        "https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js">
      </script>
   </head>
   <body>
      <h2>This is AngularJS Application</h2> 
      <div ng-app = "mainApp" ng-controller = "studentController">
         Enter first name: <input type = "text" ng-model = "student.firstName">
         <br><br>
         Enter last name: <input type = "text" ng-model = "student.lastName">
         <br><br>
         You are entering: {{student.fullName()}}
      </div> 
      <script>
         var mainApp = angular.module("mainApp", []);
         
         mainApp.controller('studentController', function($scope) {
            $scope.student = {
               firstName: "Ali",
               lastName: "Khan",
               
               fullName: function() {
                  var studentObject;
                  studentObject = $scope.student;
                  return studentObject.firstName + " " + studentObject.lastName;
               }
            };
         });
      </script>    
   </body>
</html>

Output

Application Explained

  • AngularJS Application <div> को Ng-app Mypad द्वारा परिभाषित किया जाता है.

  • AngularJS मे Scope Application Object होता है.

  • Ng Model Directives Input Field को Controlling Property मे Bind करता है.