Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error using directive #44

Open
aakoch opened this issue Jan 18, 2023 · 1 comment
Open

Error using directive #44

aakoch opened this issue Jan 18, 2023 · 1 comment

Comments

@aakoch
Copy link

aakoch commented Jan 18, 2023

I don't have much information, but I'm adding 2 attributes to some components and am getting this error:

core.mjs:6362 ERROR TypeError: Cannot read properties of undefined (reading 'pipe')
    at set setFocus [as setFocus] (angular-input-focus.mjs:50:15)
    at setInputsForProperty (core.mjs:13120:13)
    at elementPropertyInternal (core.mjs:12218:9)
    at ɵɵproperty (core.mjs:14457:9)
    at MyComponent_ng_container_5_Template (my.component.html:11:70)
    at executeTemplate (core.mjs:11835:9)
    at refreshView (core.mjs:11698:13)
    at refreshEmbeddedViews (core.mjs:12747:17)
    at refreshView (core.mjs:11722:9)
    at refreshComponent (core.mjs:12793:13)

This is the code I'm using and it is working on some page:

[libFocus]="false"
[setFocus]="focusEventEmitterMap.get('controlName')!"

The error shows up on page load.

Any ideas?

@DeanPDX
Copy link
Owner

DeanPDX commented Jan 21, 2023

If I had to guess, focusEventEmitterMap.get('controlName')! is returning a null value. The offending code might be here:

value.pipe(takeUntil(this.killSubscriptions)).subscribe(focus => this.setFocusOnElement(focus));

Are you positive that you are returning an event emitter from focusEventEmitterMap.get? It looks like it could be null but you are masking it since you're using the non-null assertion operator:

https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-0.html#non-null-assertion-operator

I'm torn between being more defensive in that code or not. Because I'm assuming if you remove the non-null assertion the code will give you a compile time error, which is probably more useful than me checking for nulls there and having the code just silently fail.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants