'Replacement of deprecated MediaQueryList.addListener() event in Angular 8
As the mozilla developers docs
says MediaQueryList
addListener is deprecated.
I'm using it in my Angular 8
. Though it's working it's linting warning in VS Code
.
what's the replacement of it?
Solution 1:[1]
Quoting from the MDN docs about MediaQueryList:
MediaQueryList.addListener()
Adds a listener to the MediaQueryListener that will run a custom callback function in response to the media query status changing. This is basically an alias forEventTarget.addEventListener()
, for backwards compatibility purposes.
addEventListener
needs an event type as the first argument, so it becomes this:
// deprecated: MediaQueryList.addListener(listener);
MediaQueryList.addEventListener('change', listener);
The same stands true for removeListener()
:
// deprecated: MediaQueryList.removeListener(listener);
MediaQueryList.removeEventListener('change', listener);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Penny Liu |