Skip to content

Commit 0c7d21c

Browse files
IlyaSurmayvalorkin
authored andcommitted
feat(loader): added ability to attach inline elements via component loader (#2458)
1 parent 6472b6f commit 0c7d21c

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/component-loader/component-loader.class.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
ComponentFactory,
77
ComponentFactoryResolver,
88
ComponentRef,
9-
ElementRef,
9+
ElementRef, EmbeddedViewRef,
1010
EventEmitter,
1111
Injector,
1212
NgZone,
@@ -30,6 +30,7 @@ export class ComponentLoader<T> {
3030

3131
public instance: T;
3232
public _componentRef: ComponentRef<T>;
33+
public _inlineViewRef: EmbeddedViewRef<T>;
3334

3435
private _providers: Provider[] = [];
3536
private _componentFactory: ComponentFactory<T>;
@@ -237,6 +238,11 @@ export class ComponentLoader<T> {
237238
}
238239
}
239240

241+
attachInline(vRef: ViewContainerRef, template: TemplateRef<any>): ComponentLoader<T> {
242+
this._inlineViewRef = vRef.createEmbeddedView(template);
243+
return this;
244+
}
245+
240246
_registerOutsideClick(): void {
241247
if (!this._componentRef || !this._componentRef.location) {
242248
return;

src/dropdown/bs-dropdown.directive.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,8 @@ export class BsDropdownDirective implements OnInit, OnDestroy {
176176
if (!this._inlinedMenu) {
177177
this._state.dropdownMenu
178178
.then((dropdownMenu: BsComponentRef<BsDropdownMenuDirective>) => {
179-
this._inlinedMenu = dropdownMenu.viewContainer.createEmbeddedView(dropdownMenu.templateRef);
179+
this._dropdown.attachInline(dropdownMenu.viewContainer, dropdownMenu.templateRef);
180+
this._inlinedMenu = this._dropdown._inlineViewRef;
180181
});
181182
}
182183

0 commit comments

Comments
 (0)