Objectives and outcomes

In this tutorial we are going to learn about angular-js $scope object. $scope object in angular-js acts as a binder between the view and the controller. It helps in changing, manipulating and removing application data. $scope object can consist of methods and properties. Example showing the use of $scope object is given below:



Javascript

<script>
var app = angular.module("myapp",[]);
app.controller("scope_control",function($scope)
{
$scope.website_name = "codeshot.in";
$scope.method1 = function()
{
return (5 * 2 + 4);
};
});
</script>


HTML code:

<html>
<head>
<meta charset="utf-8">
<title>Angularjs $scope</title>
<script src="angular-1.4.6/angular.min.js"></script>
</head>
<body>
<div ng-app="myapp" ng-controller="scope_control">
<p><b>Website name : {{website_name}}</b><br/>
<b>function result : {{method1()}}</b></p>
</div>
</body>
</html>


Website name : {{website_name}}
function result : {{method1()}}



Methods and properties of $scope object are accessed using {{}} (double curly braces).