11+ Year IT Industry Experience, Working as Technical Lead with Capgemini | Consultant | Leadership and Corporate Trainer | Motivational and Technical Speaker | Career Coach | Author | MVP | Founder Of RVS Group | Trained more than 4000+ IT professionals | Azure | DevOps | ASP.NET | C# | MVC | WEB API | ANGULAR | TYPESCRIPT | MEAN | SQL | SSRS | WEB SERVICE | WCF... https://bikeshsrivastava.blogspot.in/ http://bikeshsrivastava.com/

What is $scope in controller ?

$scope is an article information stockpiling extension, or we can comprehend it as an information distribution center which different items as Controller, Service will utilize and trade of data through it. 
you can make any sort of variables at once and utilize anyplace inside controller.$scope and $rootscope is spine of AngulerJs.
Basic Example of controller in AngularJs:-
Step 1:-Create simple HTML page.
Step 2:-Include AngularJs library  to support Angularjs in your application inside head tag with script tag.
or /use CDN URL:-<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js"></script>
<!DOCTYPE html>
<html>
<head>
<script src="angular.js"></script>
<script src="script.js"></script>
</head>
<body ng-app="mainApp">
<div ng-controller="simpleController">
<strong>First name:</strong> {{firstName}}<br />
<strong>Last name:</strong> <span ng-bind="lastName"></span><br />
<strong>Full name:</strong> {{getFullName()}}<br />
<br />
<label>Set the first name: <input type="text" ng-model="firstName"/></label><br />
<label>Set the last name: <input type="text" ng-model="lastName"/></label>
</div>
</body>
</html>
Step 3:-Create Controller:-script.js file
var mainApp = angular.module("mainApp", []);
mainApp.controller('simpleController', function($scope) 
{
// Initialize the model variables
$scope.firstName = "Bikesh";
$scope.lastName = "Srivastava";
// Define utility functions
$scope.getFullName = function ()
{
return $scope.firstName + " " + $scope.lastName;
};
});
Description:-
First of all  i've created a $scope variable name is"firstName " and set value="Bikesh" and now we are using single controller name is "simpleController " so I  able to use "Bikesh"  on my HTML Part with ng-model or expression {{firstName}}.  But you need to inject $scope in controller.
You have just read an article that categorized by title AngularJs by title What is $scope in controller ?. You can bookmark this page with a URL https://bikeshsrivastava.blogspot.com/2016/01/what-is-sope-in-controller.html. Thank You!
Author: Bikesh Srivastava - Tuesday, January 19, 2016

1 comments for "What is $scope in controller ?"

Life Is Complicated, But Now programmer Can Keep It Simple.