0

I have a plunker here - https://stackblitz.com/edit/ng-first-v-last-wide-labels?file=src%2Fapp%2Fbar-chart.ts

I have a d3 chart in an Angular app.

I'm trying to capture the screen size and do something different when hovering over the bars below a screen size.

I'm trying to do this using

if (window.screen.width > 500) {
    alert('small')
}

This alerts all the time and not only when below 500

How can I capture screen size so I can use it in the code

2
  • 2
    Did you mean window.screen.width < 500? Commented Nov 19, 2018 at 15:27
  • It doesn't really matter I just need to be able to detect if the window is bigger or smaller than a certain size. I think I have it working now with window.innerWidth < 600 Commented Nov 19, 2018 at 15:32

1 Answer 1

1

I've got the same issue,

this is how I fixed it

  public height = window.innerHeight;
  public width = window.innerWidth;

and in the ngOnInit you do your verification for the alert

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.