“$rootScope” is a parent object of all “$scope” angular objects created in a web page.
- Step 1:- Angular parser first encounters the “ng-app” directive and creates a “$rootScope” object in memory.
- Step 2:- Angular parser moves ahead and finds the expression {{SomeValue}}. It creates a variable
- Step 3:- Parser then finds the first “DIV” tag with “ng-controller” directive which is pointing to “Function1” controller. Looking at the “ng-controller” directive it creates a “$scope” object instance for “Function1” controller. This object it then attaches to “$rootScope” object.
- Step 4:- Step 3 is then repeated by the parser every time it finds a “ng-controller” directive tag. Step 5 and Step 6 is the repetition of Step 3.
------------------------
index.html
---------------------------
<!DOCTYPE html>
<html lang="en-US">
<script
src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
<script src="app.js"></script>
<body ng-app="myApp" id=1>
Global value is {{Counter}}<br />
<div ng-controller="Function1">
Child Instance of {{ControllerName}} created :- {{Counter}}
</div><br />
<div ng-controller="Function2">
Child Instance of {{ControllerName}} created :- {{Counter}}
</div><br />
<div ng-controller="Function1">
Child Instance of {{ControllerName}} created :- {{Counter}}
</div><br />
<div ng-controller="Function2">
Child Instance of {{ControllerName}} created :- {{Counter}}
</div><br />
</body>
</html>
-----------------------------
app.js
----------------------------------
var app = angular.module("myApp", []); // creating a APP
app.controller("Function1", function($scope, $rootScope){
$rootScope.Counter = (($rootScope.Counter || 0) + 1);
$scope.Counter = $rootScope.Counter;
});
app.controller("Function2", function($scope, $rootScope){
$rootScope.Counter = (($rootScope.Counter || 0) + 1);
$scope.Counter = $rootScope.Counter;
});
Here is output of this program :
Global value is 4
Child Instance of created :- 1
Child Instance of created :- 2
Child Instance of created :- 3
Child Instance of created :- 4
Hello Buddy,
ReplyDeleteGratitude for putting up this prolific article! You truly make everything a cake walk. Genuinely good stuff, saving time and energy.
Is it possible to implement a server side feature that will export PivotGrid view to Excel/PDF/Word files based on the same datasource that angular control (ej-pivotgrid) is?
I mean this structure:
$scope.datasource = {
data: [],
values: [],
rows: [],
columns: []
};
If yes can you direct me in the right way?
But great job man, do keep posted with the new updates.
Merci Beaucoup,