-
-
Notifications
You must be signed in to change notification settings - Fork 486
Description
I am using angular 11.
I use ResizeSensor like below
`
export function resized(element: HTMLElement): Observable<{ width: number; height: number }> {
let resizeSensor: ResizeSensor | undefined;
let handlers: NodeEventHandler[] = [];
const onResize = (size: { width: number; height: number }) => {
handlers.forEach(handler => handler(size));
};
return fromEventPattern(
handler => {
if (!resizeSensor) {
resizeSensor = new ResizeSensor(element, onResize);
}
handlers.push(handler);
},
handler => {
handlers = handlers.filter(activeHandler => activeHandler !== handler);
if (!handlers.length && resizeSensor) {
resizeSensor.detach();
resizeSensor = undefined;
}
},
);
}`
And in my ngAfterViewInit I use this func like this
this.viewChanges$ = resized(this.elementRef.nativeElement) .pipe( pluck('width'), tap((newWidth: number) => { // my code }), );
When this component gets hidden and shown again using the *ngIf directive, suddenly the observer stops emitting values.
<ng-container *ngIf="show"> <componentusingcss-element-queries><componentusingcss-element-queries> </ng-container>
Is there something like if the element being observed by this library is hidden using ngIf, and shown again, it will stop observing?