0
angular.module(module.name).directive(current.name, ['$timeout', function (timeout) {
return {
    restrict: 'A',

    link: function (scope, element, attrs) {
        element[0].style.margin = '0.1px';

        timeout(function () {
            element[0].style.margin = '0px';
        }, 3000);
    }
}
}]);

The above angular code is something that I wrote so when the browser loads it'll repaint the browser after to show the content on a single page app properly. However I have come to another issue where I need to do this on Resize.

I want to be able to use the same function below and add resize to it.. I'm a bit lost if I can add resize to this or will I need to write a different script.

I'm still coming to grips with angular so I'm looking for an answer that will explain this properly and what would be the best practise for what I want.

Nick Tomlin
  • 28,402
  • 11
  • 61
  • 90
Max Lynn
  • 1,738
  • 6
  • 22
  • 35
  • You can listen to the `resize` event on window, or use something like [ngResize](https://github.com/danmasta/ngResize) – Nick Tomlin Jul 01 '15 at 16:57
  • Yeah, I should have mentioned that I actually know I need to use $window and resize however I'm unsure on how to implement that to the above code – Max Lynn Jul 01 '15 at 16:59
  • In this post, http://stackoverflow.com/questions/23044338/window-resize-directive , the first reply has a good jsfiddle which demonstrates the `resize` directive and event : http://jsfiddle.net/zbjLh/270/ – bob.mazzo Jul 01 '15 at 17:07

1 Answers1

0

Do you want to apply it on any resize of the window or just below particular ratio/size?

If you want on any resize of the window, take a look at this JSFiddle

scope.$watch(scope.getWindowDimensions, function (newValue, oldValue) {...
SDekov
  • 9,276
  • 1
  • 20
  • 50
  • Although this wasn't what i wanted it gave me a good understanding of what I needed to do which is why i have given you the green tick. – Max Lynn Jul 03 '15 at 15:43