Today we will discuss about "$scope in Angularjs".
First of all what is $scope ?
A $scope is an object instance of a controller. When ng-controller directive is encountered at that time $scope gets created.
In the below code we have two controllers firstController and secondController. In both the controllers we have a ControllerName variable.
$scope.ControllerName = firstController";
$scope.ControllerName = secondController;
We can attach the both controllers to HTML UI where we are using ng-controller directive.
You can see in the below code where ng-controller directive attaches firstController with firstDiv tag and secondController with secondDiv tag.
<div id=firstDiv"; ng-controller=firstController>
<div id=secondDiv"; ng-controller=secondController">
Now the internal functionality is, when HTML DOM is created the Angular parser starts running on the DOM.
Parser first finds ng-controller directive then both controller one by one(firstContorller and secondController) and creates a news instance of $scope object and connects to respective div i.e firstDiv, secondDiv.