What is scope in AngularJS ?

Shradha Sapat Buran

02 Jul, 2024

What is scope in AngularJS ?

The Scope in AngularJS is the binding part between HTML (view) and JavaScript (controller) and it is a built-in object. It contains application data and objects. It is available for both the view and the controller. It is an object with available properties and methods. There are two types of scopes in Angular JS.


How to use the Scope?

When we make a controller in AngularJS, we will pass the $scope object as an argument. In AngularJS, it creates and injects a different $scope object into each controller in an application. Thus, the data and methods attached to $scope inside one controller cannot be accessed on another controller. Amidst the nested controller, the child controller will acquire the parent controller’s scope object. Accordingly, the child controller can access properties added to the parent controller but the parent controller cannot access properties annexed to the child controller.


Understanding the Scope: If we see an AngularJS application that consists of:
1.The HTML view.
2.Model, the data which is available for the current view.
3.Controller, the JavaScript function that makes/changes/removes/controls the data.

The scope is the model and it is a JavaScript object with properties and methods which are available for both the view and the controller.

lily and 4 people like this