What is $scope in AngularJS?
$scope in AngularJS is a built-in object which basically binds the “controller” and the “view”. One can define member variables in the scope within the controller which can then be accessed by the view.
Consider example below:
Setting up or adding Behavior
In order to react to events or execute some sort of computation/processing in the View, we must provide behavior to the scope.
Behaviors are added to scope objects to respond to specific events that may be triggered by the View. Once the behavior is defined in the controller, it can be accessed by the view.
In the browser you will see a concatenation of both the values of Guru & 99 which were passed to the behavior in the controller.
- Various member variables can be added to the scope object which can then be referenced in the view.
- Behavior can be added to work with events which are generated for actions performed by the user.
- The angularjs
$rootScopeis the scope for the entire application. An application can only have one $rootScope and is used like a global variable. In Angular JS $scopes are child scopes and $rootScope is parent scope