AngularJS – window resize and angular get element height in controller

Example 1 : angular get element height in controller

In this Post We Will Explain About is AngularJS – window resize and angular get element height in controller With Example and Demo.Welcome on – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to angular get element height in controllerExample

In this post we will show you Best way to implement angularjs watch element height window innerheight AngularJS, hear for AngularJS – How to get window height in angular jswith Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

READ :  Angular Remove Duplicates value From Array

Include External Libs

angular-1.0.0.js  //

Step 1 : HTML Part

<div ng-app="liveApp" ng-controller="resizeCtrl" ng-style="style()" resize>your Browse window.height: {{windowHeight}}
    <br />your Browser window.width: {{windowWidth}}
    <br />
<h1>BIGGEST AND FASTEST Web Tutorials </h1>

<p>We are Web Technology Experts and Team who provide you very Important information on Web Development information,Examples and Demo, Interview Questions and Answers, live project problem solution and their solution and online free tutorials – “”.</p>

<p><mark>You can download free 100% source code and Demo from below link.</mark></p>

Step 2 : javascript Part

var liveApp = angular.module('liveApp', []);

function resizeCtrl($scope) {
    /* Logic here or some angular code goes here */

liveApp.directive('resize', function ($window) {
    return function (scope, element) {
        var w = angular.element($window);
        scope.getWindowDimensions = function () {
            return {
                'h': w.height(),
                'w': w.width()
        scope.$watch(scope.getWindowDimensions, function (customval, oldValue) {
            scope.windowHeight = customval.h;
            scope.windowWidth = customval.w;

   = function () {
                return {
                    'height': (customval.h - 100) + 'px',
                        'width': (customval.w - 100) + 'px'

        }, true);

        w.bind('resize', function () {

Step 3 : CSS Part

div {
    border:2px solid green;


READ :  C# Console Hello World Application in visual studio

Example 2 : angularjs set element height in controller

HTML Part (index.html)

<!DOCTYPE html>
    <script  src=""></script>
  <body ng-app="liveApp">
    <h1 my-directive>Hello ! width: {{width}}, height: {{height}}


angular.module('liveApp', [])
  .directive('myDirective', function($timeout) {
    return {
        restrict: 'A',
        link: function(scope, element) {
            scope.height = element.prop('offsetHeight');
            scope.width = element.prop('offsetWidth');

You can download free 100% source code and Demo from below link.


I hope you have Got What is angularjs get window height and width examples And how it works.I would Like to have FeadBack From My Blog( readers.Your Valuable FeadBack,Any Question,or any Comments abaout This Article( Are Most Always Welcome.