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:


var app = angular.module("myapp",[]);
$scope.website_name = "codeshot.in";
$scope.method1 = function()
return (5 * 2 + 4);

HTML code:

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

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

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