The scope is the binding part between the JavaScript (controller) and the HTML (view).
If we consider an AngularJS application to consist of:
Then the scope is the Model.
A scope is a JavaScript object with properties and methods, which are available for the view and the controller both.
$scope object pass as an argument, when we make a controller in AngularJS.
Open the Example1.html file and add the code in it.
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.7.8/angular.min.js"></script> <title></title> </head> <body> <div ng-app="myApp" ng-controller="myCtrl"> <h2>{{title}}</h2> </div> <script> var app = angular.module('myApp', []); app.controller('myCtrl', function ($scope) { $scope.title = "The CodeHubs"; }); </script> </body> </html>
If we make changes in the view, the model and the controller will be updated automatically:
Application explained:
Output:
All applications have a $rootScope. The rootScope is available in the entire application. $rootScope is the scope created on the HTML element that holds the ng-app directive.
If a variable has the same name in both the rootScope and in the current scope, the application uses the one in the current scope.
Open the Example1.html file and add the code in it.
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.7.8/angular.min.js"></script> <title></title> </head> <body ng-app="myApp"> <h1>{{title}}</h1> <div ng-controller="myCtrl"> <h1>{{title}}</h1> </div> <h1>{{title}}</h1> <script> var app = angular.module('myApp', []); app.run(function ($rootScope) { $rootScope.title = 'The rootScope'; }); app.controller('myCtrl', function ($scope) { $scope.title = "The Current Scope"; }); </script> </body> </html>
A variable named “title” exists in both the rootScope and in the controller’s scope.
Output:
In this article, we have to show Create and Used PIPE in angular
In this article, we have to show Create and Used PIPE in angular
In this article, we have to show Create and Used PIPE in angular