fix(elements): always check to create strategy (#23825)
PR Close #23825
This commit is contained in:
parent
c4221dad11
commit
b1cda3639f
|
@ -135,16 +135,29 @@ export function createCustomElement<P>(
|
||||||
|
|
||||||
constructor(injector?: Injector) {
|
constructor(injector?: Injector) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
|
// Note that some polyfills (e.g. document-register-element) do not call the constructor.
|
||||||
|
// Do not assume this strategy has been created.
|
||||||
|
// TODO(andrewseguin): Add e2e tests that cover cases where the constructor isn't called. For
|
||||||
|
// now this is tested using a Google internal test suite.
|
||||||
this.ngElementStrategy = strategyFactory.create(injector || config.injector);
|
this.ngElementStrategy = strategyFactory.create(injector || config.injector);
|
||||||
}
|
}
|
||||||
|
|
||||||
attributeChangedCallback(
|
attributeChangedCallback(
|
||||||
attrName: string, oldValue: string|null, newValue: string, namespace?: string): void {
|
attrName: string, oldValue: string|null, newValue: string, namespace?: string): void {
|
||||||
|
if (!this.ngElementStrategy) {
|
||||||
|
this.ngElementStrategy = strategyFactory.create(config.injector);
|
||||||
|
}
|
||||||
|
|
||||||
const propName = attributeToPropertyInputs[attrName] !;
|
const propName = attributeToPropertyInputs[attrName] !;
|
||||||
this.ngElementStrategy.setInputValue(propName, newValue);
|
this.ngElementStrategy.setInputValue(propName, newValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
connectedCallback(): void {
|
connectedCallback(): void {
|
||||||
|
if (!this.ngElementStrategy) {
|
||||||
|
this.ngElementStrategy = strategyFactory.create(config.injector);
|
||||||
|
}
|
||||||
|
|
||||||
this.ngElementStrategy.connect(this);
|
this.ngElementStrategy.connect(this);
|
||||||
|
|
||||||
// Listen for events from the strategy and dispatch them as custom events
|
// Listen for events from the strategy and dispatch them as custom events
|
||||||
|
@ -155,7 +168,9 @@ export function createCustomElement<P>(
|
||||||
}
|
}
|
||||||
|
|
||||||
disconnectedCallback(): void {
|
disconnectedCallback(): void {
|
||||||
this.ngElementStrategy.disconnect();
|
if (this.ngElementStrategy) {
|
||||||
|
this.ngElementStrategy.disconnect();
|
||||||
|
}
|
||||||
|
|
||||||
if (this.ngElementEventsSubscription) {
|
if (this.ngElementEventsSubscription) {
|
||||||
this.ngElementEventsSubscription.unsubscribe();
|
this.ngElementEventsSubscription.unsubscribe();
|
||||||
|
|
Loading…
Reference in New Issue