I need to make a structural directive that will display the element depending on the width of the screen.
My example work, but it skip at medium size. How to fix it?
The issue is that you are overwriting the window.onresize
value.
I suggest using a Subject
having the onresize
value then subscribe to the subject in the different directive instances.
public windowResize$ = new BehaviorSubject<number>(window.innerWidth);
window.onresize = event => {
this.windowResize$.next(window.innerWidth);
};
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.