Skip to content

Commit e21fe9a

Browse files
committed
fix(template): handle delayed content in VirtualView directive
Enhanced `#showContentWhenDisabled` to support cases where content availability is deferred, using `effectOnceIf` for reactive content rendering.
1 parent 3e6e47b commit e21fe9a

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

libs/template/virtual-view/src/lib/virtual-view.directive.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,12 +413,23 @@ export class RxVirtualView
413413
* @private
414414
*/
415415
#showContentWhenDisabled() {
416-
const content = this.#content();
417-
if (content) {
416+
const render = (content: _RxVirtualViewContent) => {
418417
this.#contentIsShown = true;
419418
this.#placeholderVisible.set(false);
420419
content.viewContainerRef.createEmbeddedView(content.templateRef);
421420
this.visibilityChanged.emit({ content: true, placeholder: false });
421+
};
422+
423+
if (this.#content()) {
424+
render(this.#content()!);
425+
} else {
426+
// if the content is not available immediately, we register an effect to wait for it
427+
// e.g., when the content is inside a switch block that is not immediately active
428+
effectOnceIf(
429+
() => this.#content(),
430+
(content) => render(content),
431+
{ injector: this.#injector },
432+
);
422433
}
423434
}
424435

0 commit comments

Comments
 (0)