Scope Object in AngularJS

A Scope is a Binding part in AngularJS between an HTML design (View) and the JavaScript(controller).

A Scope is available for both view and also controller.

The Scope is an object with all properties and methods.

$scope.

When a controller is made in AngularJS $scope has to provide as an argument.

Example:

< div ng-app="appname" ng-controller="controllername">
< h1 >
{{yourname}}
< /h1 >
< /div >
< script >
var app = angular.module('appname',[ ])
app.controller('controllername',function($scope) {
$scope.yourname= "AngularJS";
});
< /script >

How scope can be Understand in a AngularJS

When a property is added to the $scope an object in an controller ,or a view HTML gets access for all these attributes.


In an view $scope is not used but we just prefer only {{myname}}.

Working with Scope in AngularJS

If user has designed an AngularJS an application mainly it consists as:

i. A View , which is a HTML code.

ii. Model it is a data available for a view.

iii. Controller its an Javascript function that basically changes/controller.

Which Scope is Active

In a working scope it is important to consider a present scope.

In an any example its mandatory that scope but also a applications there can be sections in DOM object.

Example:

< div ng-app="appname" ng-controller="controllername">
< ul >
< li ng-repeat="y in name">{{y}} >
< li >
< /div >
script >
var app = angular.module('appname',[ ])
app.controller('controllername',function($scope) {
$scope.names= ["Firstname","Lastname","Email"];
});
< /script >

The root Scope

All AngularJS having $rootScope which can be created on an HTML element that contains an ng-app directive.