---
title: "Explain the concept of \"scope\" in AngularJS"  
description: "Explain the concept of \"scope\" in AngularJS"  
author: "Revati S Misra"  
published: 2024-06-17  
updated: 2024-06-17  
canonical: https://www.mindstick.com/forum/160746/explain-the-concept-of-scope-in-angularjs  
category: "angular js"  
tags: ["javascript", "angular js", "angularjs scope"]  
reading_time: 3 minutes  

---

# Explain the concept of "scope" in AngularJS

[Explain the concept](https://www.mindstick.com/forum/159605/explain-the-concept-of-unique-key-violation-error) of "scope" in AngularJS

## Replies

### Reply by Ashutosh Patel

### Scope in Angular JS

In AngularJS, "scope" refers to an object that binds a "controller" and a "view" or HTML. It acts as a bridge between the view and the business logic defined in the controller. Here is a detailed explanation of what a scope is and how it works in AngularJS.

#### Definition and purpose

## Object

Scope is a JavaScript object that represents an application model. It is a word search feature.\
**Binding**

Binds HTML (view) and JavaScript (controller). Any changes made to the scope object in the controller are immediately reflected in the view, and vice versa.

#### Hierarchical Structure

## Inheritance

Scopes in AngularJS follow a hierarchical structure similar to the DOM structure of application components.\
**Child scopes**

Each controller in AngularJS creates its own scope, which inherits from its parent scope. This allows properties defined in parent scopes to be accessed in child scopes, making it easier to share data between components.

#### Scope Lifecycle

## Creation

Scopes are created for each controller when AngularJS compiles and links the corresponding HTML template.\
**Digest Cycle**

AngularJS uses a digest cycle to detect scope changes. During the digestion cycle, the angler compares the previous and current values ​​of the scope's characteristics to update the view accordingly.

#### Two-Way Data Binding

## Synchronization

One of the key features of scope in AngularJS is the ability to provide two-way data binding between model (controller) and view. Changes to the view update the model and changes to the model automatically update the view.

#### Directives and Scope

## Directive Scope

Directives in AngularJS can create and modify their own scope. This allows instructions to contain both behavior and data, preventing scope contamination and conflicts with other parts of the application.

## Example-

```javascript
<!DOCTYPE html>
<html data-ng-app="myApp">

<head>
    <meta charset='utf-8'>
    <meta http-equiv='X-UA-Compatible' content='IE=edge'>
    <title>ng-Root Scope</title>
    <meta name='viewport' content='width=device-width, initial-scale=1'>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.8.2/angular.min.js"></script>
</head>

<body>
    <div data-ng-controller="MyController">
       <!-- Data binding -->
        <input type="text" ng-model="name">
        <!-- bind the data which type in input field -->
        <p>Hello, {{ name }}!</p>
    </div>

    <script>
        var app=  angular.module("myApp", [])
        .controller("MyController", function($scope){
            // the scope of $scope.name is only within this controller
            $scope.name = "John"; // default name
        });

    </script>

</body>
</html>
```

## In the example above

Here, in the controller, `$scope.name` is bound as an **input** field with a paragraph (`<p>`) tag. Any changes to the name entered in the input field will automatically update the paragraph content due to AngularJS's **two-way data binding** facilitated by **scope**

\
**Scope** in AngularJS are important for data management and consistency between the **controller** and the **view**. It establishes a clear separation between concerns with presentation (**HTML**) and business logic (**JavaScript**), allowing for a more structured and manageable approach to web application development

**Also, Read:** [Difference between $rootScope and $scope in AngularJS.](https://www.mindstick.com/forum/160755/difference-between-rootscope-and-scope-in-angularjs)


---

Original Source: https://www.mindstick.com/forum/160746/explain-the-concept-of-scope-in-angularjs

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
