Skip to content

[feature][@angular/elements] Expose ComponentNgElementStrategy #33490

Description

@flash-me

🚀 feature request

Relevant Package

@angular/elements

Description

There is no "easy" way to pass custom lifecycle callbacks for CustomElements.
We may pass a custom NgElementStrategyFactory to createCustomElement, but when looking at ComponentNgElementStrategy, this is not something that should be done by the average angular developer.

Describe the solution you'd like

  1. Suggestion: You may expose ComponentNgElementStrategy. That way we could extend it and override the methods + call the super methods.
  2. Suggestion: Extend createCustomElement to directly pass the optional custom callbacks, which in turn are called internally. Maybe an object of:
export interface CustomElementCallbacks {
  /** When upgraded, its constructor is run, with no arguments */
  constructedCallback()?: void;
  /** When it becomes connected, its connectedCallback is called, with no arguments */
  connectedCallback()?: void;
  /** When it becomes disconnected, its disconnectedCallback is called, with no arguments */
  disconnectedCallback()?: void;
  /** When it is adopted into a new document, its adoptedCallback is called, given the old document and new document as arguments */
  adoptedCallback()?: void;
  /** 
  * When any of its attributes are changed, appended, removed, or replaced, 
  * its attributeChangedCallback is called, given 
  * the attribute's local name, old value, new value 
  */
  attributeChangedCallback(attrName: string, oldVal?: any, newVal?: any)?: void;
}

Describe alternatives you've considered

Just copy the code from here? (Not thinking about compatibility on version changes, though....)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: elementsIssues related to Angular ElementsfeatureLabel used to distinguish feature request from other issues

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions