JSFiddle - React, Tailwind, and code Playground

by Garry

HTML

<div ng-app="miniapp" ng-controller="AppController">
    
    <div class="fess" ng-style="resizeWithOffset(165)" 
       resize
     notifier="notifyServiceOnChage(params)"
    >
    
    window.height: {{windowHeight}} <br />
    window.width: {{windowWidth}} <br />
    </div>
</div>

CSS

.fess { border:1px solid red; }

JavaScript

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

function AppController($scope) {
   $scope.notifyServiceOnChage = function(){
     console.log($scope.windowHeight);
  };
}

app.directive('resize', function ($window) {
    return function (scope, element, attr) {
        
        function resize () {
            
            //** Use window will listen to the global window change,
            // If you want to destroy (unbind) the window event,  you can :
            // var window = angular.element($window)
            // call window on-resize: window.on('resize', funciton () {} ) 
            // destroy on scope.$on('$destroy', function () { window.off('resize') })
            //
            var windowHeight = window.innerHeight,
                windowWidth  = window.innerWidth;
            
            scope.windowHeight = windowHeight;
            scope.windowWidth  = windowWidth;
            
            console.log('w.innerHeight', windowHeight);
            console.log('w.innerWidth', windowWidth);
            
            //** If want to apply style on element, can do something like:
            var elemStyle = {
                width: windowWidth + 'px',
                height: windowHeight + 'px'
            };
            
            element.css(elemStyle);
        }       
        resize();

        //** On resize
        window.onresize = function () {
            resize();
            scope.$apply();
        }
    }
});