Wednesday, July 8, 2015

$window in AngularJS

$window provides a shortcut to access the browsers window object’s in AngularJS, using $window we can access the properties and events of the browser’s window object.

The following is the syntax to access $window property using AngularJS
$window.<windows property/event>

The following example shows how to get the browser window’s  width and height properties using $window

<html ng-app>
  <head>
    <meta charset="utf-8">
    <title>AngularJS - $window Basic</title>
    <script src="angular.min.js"></script>
    <script>
      function winController($scope, $window){
              $scope.Width = $window.innerWidth;
              $scope.Height = $window.innerHeight;
      }
    </script>
  </head>
  <body>
          <div ng-controller="winController">
                   Width: {{Width}} <br/>
                   Height: {{Height}} <br/>
          </div>
  </body>
</html>

Output


Search Flipkart Products:
Flipkart.com

No comments: