The child scope is inheriting properties from the base or parent scope.
An isolated scopes does not prototypically (“child scope”) inherit from its parent scope.
Syntax for scope in Angular JS:
Sample coding for scope in AngularJS:
Data:
The msg data been defined for our AngularJS Application.
Logic:
Controller logic for the AngularJS application.
HTML:
Viewable HTML contents in AngularJS Application.
Code Explanation for scope in AngularJS:
AngularJS is distributed as a JavaScript file, and can be added to a HTML page with a <script> tag.
The AngularJS application is defined by ng-app="myApp". The application runs inside the
<div> tag. It’s also used to define a <div> tag as a root element.
The ng-controller=”scopeCtrl” is an AngularJS directive. It is used to define a controller name as “scopeCtrl”.
{{ msg }} is a used to bind the controller value by using the scope object.
angular.module function is used to create a module. Here has passed an empty array to it.
Here we have declared a controller scopeCtrl module using apps.controller() function.
The value of the controller modules is stored in scope object. In AngularJS, $scope is passed as first argument to apps.controller during its constructor definition.
Here we have set the value of $scope.msg as “Welcome To AngularJS Tutorials” which are to be used to display the {{ msg }} value in the HTML <div> element.
Sample output:
The output displays a message of a string {{ msg }} by using a $scope object