Skip to content

Commit

Permalink
feat(loader): added ability to attach inline elements via component l…
Browse files Browse the repository at this point in the history
…oader (#2458)
  • Loading branch information
IlyaSurmay authored and valorkin committed Aug 18, 2017
1 parent 6472b6f commit 0c7d21c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/component-loader/component-loader.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
ComponentFactory,
ComponentFactoryResolver,
ComponentRef,
ElementRef,
ElementRef, EmbeddedViewRef,
EventEmitter,
Injector,
NgZone,
Expand All @@ -30,6 +30,7 @@ export class ComponentLoader<T> {

public instance: T;
public _componentRef: ComponentRef<T>;
public _inlineViewRef: EmbeddedViewRef<T>;

private _providers: Provider[] = [];
private _componentFactory: ComponentFactory<T>;
Expand Down Expand Up @@ -237,6 +238,11 @@ export class ComponentLoader<T> {
}
}

attachInline(vRef: ViewContainerRef, template: TemplateRef<any>): ComponentLoader<T> {
this._inlineViewRef = vRef.createEmbeddedView(template);
return this;
}

_registerOutsideClick(): void {
if (!this._componentRef || !this._componentRef.location) {
return;
Expand Down
3 changes: 2 additions & 1 deletion src/dropdown/bs-dropdown.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ export class BsDropdownDirective implements OnInit, OnDestroy {
if (!this._inlinedMenu) {
this._state.dropdownMenu
.then((dropdownMenu: BsComponentRef<BsDropdownMenuDirective>) => {
this._inlinedMenu = dropdownMenu.viewContainer.createEmbeddedView(dropdownMenu.templateRef);
this._dropdown.attachInline(dropdownMenu.viewContainer, dropdownMenu.templateRef);
this._inlinedMenu = this._dropdown._inlineViewRef;
});
}

Expand Down

0 comments on commit 0c7d21c

Please sign in to comment.