Reputation: 1115
I'm developing an Angular Component and i use this css code.
:host {
display: block;
width: 100%;
}
The ideia is to make the component as responsive as possible.
My problem is that i need to do some logic whenever my component width changes. The prefered way (MutationObserver) does not working with component width set by percentage because if the with changes it will be always 100% so the callback of the mutation observer doesnt get fired.
I read somewhere about putting the logic in the DoCheck licycle hook, can some one tell me if there are any other good way to do what i nedd?
Upvotes: 0
Views: 306
Reputation: 189
I think you have two options:
window.addEventListener('resize', reportWindowSize);
At the first loading you have to save the original dimension of the div and when the window is resized, you check the original vs current dimension of the div and if it is changed do your custom logic.Upvotes: 1