Angular use scope object Example

Angular use scope object Example

Today, We want to share with you Angular use scope object Example.
In this post we will show you Angular use scope object Example, hear for Angular use scope object Example we will give you demo and example for implement.
In this post, we will learn about Angular use scope object Example with an example.

The $scope varible in an AngularJS is a one type of built-in object, which contains (join) web-application data and all methods.

AngularJS : Defination of Scope.

The scope is the binding part between the HTML page (view-side) and the JavaScript side (controller part). The scope is an one type of object with the available some properties and methods.Simple Means (Scope is join between html page and controller)

READ :  Angular4 Send Email using PHP - Email sending with Angular4

The main purpose of a Scope variable is to “join two phase” the presentation view and the business logic controller of your web-application.

The Scope main contains the model of data. In controllers logic data, model data is accessed via using $scope object. Simple Means : connects to controllers and view.

Main purpose of Scope

  • View, which is the HTML.
  • Model ->data available for the current view
  • Controller – >JavaScript function that makes and changes and removes the controls.

Then conclusion is the scope is the Model.

The Scope Life Cycle

1. Creation phase or init
2. Watcher registration phase in angular
3. Model mutation phase in angular
4. Mutation observation phase
5. Scope destruction phase in angular

<!DOCTYPE html>
<html >
<head>
    <title>AngualrJS $scope object</title>
    <script src="http://infinityknow.com/libs/angular.min.js"></script>
</head>
<body ng-app="ngApp">
    <div ng-controller="firstCtrl">
        StatusMessage: <br />
        {{statusmsg}}<br />
        <span ng-bind="statusmsg"></span> <br />
        <input type="text" ng-model="statusmsg" /> 
    </div>
    <script>
        var ngApp = angular.module('ngApp', []);

        ngApp.controller('firstCtrl', function ($scope) {
            $scope.statusmsg = "Hello World!";        
        });
    </script>
</body>
</html>

Simple The AngularJS Life Cycle

  • In angularjs,The Bootstrap Phase.
  • In angularjs,The Compilation Phase.
  • In angularjs,The Runtime Data Binding Phase.
READ :  Top 10 Advanced Angular 6 Interview Questions Answers

The Scope variable is a one special type of object or variable in AngularJS and it act’s like connects between controller side and view side. It can hold any type of valid javascript type including any object.

View Demo

Add a Comment

Your email address will not be published. Required fields are marked *