What is $scope in AngularJS?

Angularjs $scope is nothing but just api data showed view file. I will Explain.
The controller creates two properties (variables) in the scope (firstName and lastName).
The ng-model directives bind the input fields to the controller properties (firstName and lastName).


 

Example Code:

<script>
function ControllerName($scope){
     $scope.Name= 'Dev2tricks'
    $scope.mysite= 'devtotricks.blogspot.com'

}
</script>

HTML Code:

<div ng-controller="ControllerName">
<p>{{data.Name}}</p>
<p>{{data.mysite}}</p>

output:

Dev2tricks
devtotricks.blogspot.com

or

<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
    $scope.Name= "Dev2tricks";
    $scope.mysite= "devtotricks.blogspot.in";
});
</script>

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

Name: <input type="text" ng-model="Name"><br>
Mysite: <input type="text" ng-model="mysite"><br>
<br>
Details: {{Name+ " " + mysite}}

</div>


Output

Details : Dev2tricks devtotricks.blogspot.in







What is $scope in AngularJS? Dev2Tricks 5 of 5
Angularjs $scope is nothing but just api data showed view file. I will Explain. The controller creates two properties (variables) in the ...

Share this

Related Posts

Previous
Next Post »

3 comments

comments
2 February 2016 at 22:15 delete

Nice. But Can you explain some more deeply...

Reply
avatar
2 February 2016 at 22:16 delete

Nice. But Can you explain some more deeply...

Reply
avatar
7 February 2016 at 21:33 delete

This script brings the datas. If any more get me at methababublog@gmail.com

Reply
avatar