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

Added a null check before accessing this.$instance in ngOnChanges() #112

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/slick.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,10 @@ export class SlickCarouselComponent implements OnDestroy, OnChanges, AfterViewIn
this.initialized = false;
}

// Added a check to ensure that this.$instance is defined before accessing it to prevent TypeError: Cannot read properties of undefined (reading 'slick')
// This helps prevent errors when ngOnChanges() is called and ensures that the Slick Carousel component is properly initialized before accessing its properties.
ngOnChanges(changes: SimpleChanges): void {
if (this.initialized) {
if (this.initialized && this.$instance) {
const config = changes['config'];
if (config.previousValue !== config.currentValue && config.currentValue !== undefined) {
const refresh = config.currentValue['refresh'];
Expand Down