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

How to attach event Listener to the sidebar nav items? #276

Open
cevhyruz opened this issue Feb 11, 2025 · 2 comments
Open

How to attach event Listener to the sidebar nav items? #276

cevhyruz opened this issue Feb 11, 2025 · 2 comments

Comments

@cevhyruz
Copy link

Hi! Thanks for this wonderful free template! just a quick question, I want to open a dialog first then after the user confirmation then proceed to go to an external URL how should I approach this?

@xidedix
Copy link
Member

xidedix commented Feb 11, 2025

@cevhyruz

What about EventManager?
For all the links you want to open a dialog, add an id attribute to the sidebar-nav-link, sth like:

export const navItems: INavData[] = [
  {
    name: 'Link',
    url: 'your/url',
    attributes: { id: 'link-with-id' }
  }
...

then for src/app/layout/default-layout/default-layout.component.ts

// simplified for brevity, not tested code
...
readonly #document = inject(DOCUMENT);
readonly #eventManager = inject(EventManager);

ngAfterViewInit(): void {
  const id = 'link-with-id'
  const linkWithId = this.#document.getElementById(id);
  if (linkWithId) {
    this.#eventManager.addEventListener(linkWithId, 'click', ($event: MouseEvent) => {
      // your handler here
    });
  }
}

An alternative approach involves creating a dedicated route with component for external URL navigation, protected by route guards, and a service for handling dialogues.

@cevhyruz
Copy link
Author

@xidedix

Hi! Thanks for the fast response! I found out that modals are bundled for free too! 🔥

I'm really having a hard time with integrating material design so I think I'm gonna stick with the the coreUI's modal.
any pointers will be appreciated 💓

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