0

I'm kinda new to angular.

I want to have a listener for whenever width of document changes.

So first of all I decided to add a $watch like this:

$scope.$watch(function(){
    return $window.innetWidth;
}, function(n, o){
    console.log(n);
    console.log(o);
});

But it only works on page load and not on resize.

Then I decided to write a Directive like this:

app.directive('watchWidth', [function(){
        return {
            restrict: 'A',
            link: function(scope, element) {
                element.style.display = 'none';

                $scope.$watch(function () {
                    return element.innerWidth;
                }, function (n,o) {
                    console.log(n);
                    console.log(o);
                });
            }
        };
    }]);

And add directive to my ng-view:

<div watchWidth ng-view class="main-wrapper"></div>

But nothing work and no error in console and I don't know what should I do!

Any help please?

Sina Mirhejazi
  • 324
  • 2
  • 16

1 Answers1

1

Hi this is my approach to resize the a specific element

.directive('resize', function (Ls) {
    return function (scope, element, attr) {
        scope.resizeWithOffset = function (offsetH) {
                return {
                    'min-height': (window.innerHeight - offsetH) + 'px',
                    'max-height': (window.innerHeight - offsetH) + 'px'
                };
        }
    }
})

In your html it would look like this

<ion-scroll ng-style="resizeWithOffset(270)" resize></ion-scroll>

Basically the element is now resizes down to window-height - the height u can specify ( in this case 270px)

stackg91
  • 584
  • 7
  • 25