Angularjs - Controller in Hindi




AngularJS controllers एंगुलरजस applications के डेटा को नियंत्रित करते हैं एक controller angularjs application का सबसे उपयोगी हिस्सा हैं ये javascript फ़ंक्शंस हैं जो बहुसंख्यक संबंधित यूआई संबंधित कार्य करते हैं उन्हें आदर्श के लिए driver के रूप में माना जा सकता है

Application में डेटा के प्रवाह को नियंत्रित करने के लिए AngularJS नियंत्रक को एनजी-नियंत्रक instructions के साथ परिभाषित किया गया है AngularJS नियंत्रक एक javascript ऑब्जेक्ट है जिसमें attributes और फंक्शन होते हैं

किसी भी वेबसाइट को Angularjs Controller से जोड़ने के लिए ng-controller directive का उपयोग किया जाता है AngularJs के उपयोग से बनने वाली वेबसाइट Angular Controller पर आधारित होती है

Example Code

<!DOCTYPE html>
<html>
   
   <head>
      <title>Angular JS Controller</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: "Rahul",
               lastName: "Sharma",
               
               fullName: function() {
                  var studentObject;
                  studentObject = $scope.student;
                  return studentObject.firstName + " " + studentObject.lastName;
               }
            };
         });
      </script>
      
   </body>
</html>

Example Result

Angular JS Controller

This is AngularJS Application

Enter first name:

Enter last name:

You are entering: {{student.fullName()}}

Application explained

  • यहां, पर AngularJS एप्लिकेशन <div> को एनजी-ऐप मायपैड द्वारा परिभाषित किया जाता है

  • AngularJS में, स्कोप application ऑब्जेक्ट होता है

  • एनजी मॉडल directives इनपुट फ़ील्ड को नियंत्रक गुण में बाँधते हैं