Curriculum
Course: AngularJS
Login

Curriculum

AngularJS

AngularJS Tutorial

0/65
Text lesson

AngularJS Scope

Scope acts as the binding mechanism between the HTML view and the JavaScript controller, holding accessible properties and methods available to both.

How to Use the Scope?

When creating a controller in AngularJS, you include the $scope object as an argument.

Example

Properties defined in the controller can be accessed in the view.

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

<h1>{{carname}}</h1>

</div>

<script>

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

app.controller(‘myCtrl’function($scope) {
  $scope.carname = “Volvo”;
});

</script>