Skip to content
This repository has been archived by the owner on Aug 14, 2018. It is now read-only.

ComponentRef passed to RenderInput disappears after detecting changes #12

Closed
bengry opened this issue Jul 13, 2018 · 1 comment
Closed

Comments

@bengry
Copy link
Collaborator

bengry commented Jul 13, 2018

When passing a ComponentRef as a RenderInput to a component, after a change detection is triggered the component is removed from the DOM.
This doesn't happen when passing a TemplateRef or a () => HTMLElement.

Repro code:
Template

<fab-command-bar [items]="commandBarItems">
</fab-command-bar>

<button (click)="toggleRun()">Toggle change detection</button>

Component

private _customCbItemRef: ComponentRef<any>; // initialized via a `ComponentFactoryResolver`.

commandBarItems: ICommandBarItemOptions[] = [
  {
    key: 'run',
    text: 'Run',
    iconProps: {
      iconName: 'CaretRight',
    },
    disabled: true,
  },
  {
    key: 'custom-element',
    render: this._customCbItemRef
  },
];

toggleRun() {
  // Triggers change detection - `FabCommandBar` is defined as `OnPush`
  this.commandBarItems = this.commandBarItems.map(item => item.key === 'run' ? { ...item, disabled: !item.disabled } : item);
}

Expected result:

  • "Run" command bar item changes the disabled state.

Actual result:

  • run command bar item changes the disabled state.
  • custom-element command bar item disappears.
@bengry
Copy link
Collaborator Author

bengry commented Aug 12, 2018

This issue was moved to microsoft/angular-react#2

@bengry bengry closed this as completed Aug 12, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant