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

Not Working With Angular SSR Version 17 #841

Open
ahmedmohamedrashad01 opened this issue Jan 11, 2024 · 2 comments
Open

Not Working With Angular SSR Version 17 #841

ahmedmohamedrashad01 opened this issue Jan 11, 2024 · 2 comments

Comments

@ahmedmohamedrashad01
Copy link

Dears,
The library was working on last version ok without SSR but now working only on the first element of the page and all the bottom elements got hidden from the page ,
could you please help me to solve this issue ,
Thanks.

@tehcmanmax
Copy link

Hi @ahmedmohamedrashad01 ,

I had the same issue.I have a solution for you:

document.onreadystatechange = function () {
  if (document.readyState == "complete") {
    AOS.init();
  }
};

I explain in depth in this video

@DASMACHETE
Copy link

DASMACHETE commented Mar 30, 2024

Hi,

both this workarounds fixed the issue:

import { NgZone } from '@angular/core';

constructor(private ngZone: NgZone) {}

ngAfterViewInit(): void {
  if (isPlatformBrowser(this.platformId)) {
    this.ngZone.runOutsideAngular(() => {
      // Run code outside Angular zone
      if (this.document.readyState == 'complete') {
        console.log('doc loaded');
      }
      console.log('Page ready');
      AOS.init({ once: true, duration: 1000 });
      AOS.refresh();
    });
  }
}

or

constructor(@Inject(DOCUMENT) private document: Document) {}

ngAfterViewInit(): void {
  if (isPlatformBrowser(this.platformId)) {
    this.document.addEventListener('DOMContentLoaded', () => {
      console.log('doc loaded');
      console.log('Page ready');
      AOS.init({ once: true, duration: 1000 });
      AOS.refresh();
    });
  }
}

Another thing you need to change is:

import * as AOS from 'aos';

to

import AOS from 'aos';

Than you can use it like this in OnInit or AfterViewinit:

  ngOnInit(): void {
    if (isPlatformBrowser(this.platformId)) {
      this.document.addEventListener('DOMContentLoaded', () => {
        console.log('doc loaded');
        console.log('Page ready');
        AOS.init();
        AOS.refresh();
      });
    }
  }

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

3 participants