I have 4+ experience and working as software Engineer with Hytech professionals India PVT ltd and also working as Consultant,Trainer,Blogger and Author on Microsoft technologies,Also I have Trained more than 500+ IT professionals.I have knowledge about Asp.net,C#,SQL,Project management,replication,MVC,WebApi,SSRS,PostMan,TFS,SVN,Swagger,WMI,Agile,SignalR,Angularjs,IIS configuration.

Part 5::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 Part 5::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, 19 January 2016

There are currently no comments for "Part 5::What is $scope in controller ?"

Post a Comment

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