Problem
I have a simple directive that updates the sizes for a specific item. This oversees the size of the window and makes the appropriate changes.
MyApp.directive('resizeTest', ['$window', function($window) { return { restrict: 'AC', link: function(scope, element) { var w = angular.element($window); scope.$watch(function() { return { 'h': w.height(), 'w': w.width() }; }, function(newValue, oldValue) {
This works great.
It so happened that inside the div tag with which I am connected, I have a child div . When the size of the parent changes, I want to make positioning changes for the child. However, I can not start the trigger.
It is called at startup, but does not start when the item is resized or the window is changed:
MyApp.directive('centerVertical', ['$window', function($window) { return { restrict: 'AC', link: function(scope, element) { element.css({border: '1px solid #0000FF'}); scope.$watch('data.overlaytype', function() { $window.setTimeout(function() { console.log('I am: ' + element.width() + 'x' + element.height()); console.log('Parent is: ' + element.parent().width() + 'x' + element.parent().height()); }, 1); }); } }; }]);
What type of binding or clock configuration should I use to check if the parent element is resized?
Fiddle
https://jsfiddle.net/rcy63v7t/1/
source share