I'm using ngx-build-plus
for compile element to js.
Error ERROR TypeError: can't access property "events", this.ngElementStrategy is undefined
throw at line 512. And the break point is fired. But the point at line 481 isn't.
Offical repo: https://github.com/angular/elements-builds/blob/12.0.x/esm2015/src/create-custom-element.js#L55
For some reason,
createElement
passes HTML element you're creating asthis
inside constructor ofNgElementImpl
instead of instance ofNgElementImpl
. And thisthis
doesn't haveNgElementImpl
's methods or private / protected fields. The (ugly) solution would be moving allNgElementImpl
internals outside of the class, into the enclosing function:create-custom-element.ts
by moving implementation of instance methodsget ngElementStrategyImpl
andsubscribeToEvents
outside of the class.The version below is taken (and rewritten) from Angular 17.0.6 sources.
createCustomElement
from this modifiedcreate-custom-element.ts
instead of importing it from Angular Elements.version.ts
from copy-pasted Angular Elements sources.You might need to either add
"noImplicitAny": false,
to yourtsconfig.app.json
, or to further adjust the source code to avoid compilation errors. Also, consider adding/* eslint-disable */
to the top of each copy-pasted Angular Elements files to avoid linter errors.The related bug in Angular repository was marked as fixed, but it still strikes back at you in Firefox 120 as of 2023-12-11.