Saturday, August 26, 2017

$scope in angularjs

  • The $scope in an AngularJS is a built-in object
  • The $scope is glue between a controller and view (HTML).This transfers data from the controller to view and vice-versa.
  • In the controller, we can attach properties and methods to the $scope object and view can display $scope object data using an expression, ng-model, or ng-bind directive, or binding expression.
  • Each controller of application injects a different $scope object.
Example: 
JS :
MyApp.controller('DemoScope', function ($scope) {
    $scope.DemoName = "Demo scope value";
});
HTML :
    <span class="bi">Demo Controller :</span><br/>
    <div ng-controller="DemoScope">
        <span class="b">Scope value:</span> {{DemoName}}
    </div>

No comments:

Post a Comment