1

I have a custom directive that I want some logic (in an if statement) to be run when a page loads or when its resized.

So for the the page load I have the if statement at the start of the custom directive then again duplicated in the on resize.

However to avoid this duplication is it possible to do something like the below?

angular.element($window).on('resize' || 'load', function () {
    //my logic
}

Thanks.

2
  • 1
    have you tried .on('resize load', ... ? Commented May 29, 2016 at 14:15
  • That looks like it works! Commented May 29, 2016 at 14:29

1 Answer 1

1

you can simply have the events names as a string separated with a space:

angular.element($window).on('resize load', function () {
    //my logic
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.