Curriculum
Course: AngularJS
Login

Curriculum

AngularJS

AngularJS Tutorial

0/65
Text lesson

Know Your Scope

It’s crucial to be aware of which scope you are working with at any moment. In the two examples above, there’s only one scope, so scope awareness is not an issue. However, in larger applications, certain sections of the HTML DOM may only have access to specific scopes.

Example

When using the ng-repeat directive, each iteration has access to the current iteration object.

<div ng-app=”myApp” ng-controller=”myCtrl”>

<ul>
  <li ng-repeat=”x in names”>{{x}}</li>
</ul>

</div>

<script>

var app = angular.module(‘myApp’, []);

app.controller(‘myCtrl’function($scope) {
  $scope.names = [“Emil”“Tobias”“Linus”];
});

</script>

Root Scope in AngularJS is the top-level scope that is available globally across the entire application, shared by all controllers and directives unless overridden by local scopes.