question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Sidebar menu treeview not working after redirection in Angular 4

See original GitHub issue

Hi,

I’m using AdminLTE theme (2.4.0-rc) in Angular4 project. Dashboard with the sidebar menu is on url “http://host/”. When I enter this address in browser address field, everything is working correct. Problem is when app is on other url, i.e. “http://host/login” and there is link to main page or redirection in code used one of methods: this.router.navigateByUrl('/') or <a routerLink="/">. After redirection to the Dashboard by one of these methods, sidebar menu “treeview” option does not open. Therefore after redirection by <a href="/"> everything works correct. There isn’t any errors in dev console. It seems like some AdminLTE js function not see “treeview” element after redirection by Angular 4 methods. Is it any solution to make Angular 4 works as expected?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:33

github_iconTop GitHub Comments

31reactions
viniciusljcommented, Jul 30, 2018

This problem in Angular 6 and AdminLTE 3 was solved as follows:

Note: I have a Sidebar component that contains the treeview.

Import jquery and AdminLTE

import * as $ from 'jquery';
import * as AdminLte from 'admin-lte';

In ngAfterViewInit:

ngAfterViewInit() {
    $('[data-widget="treeview"]').each(function() {
        AdminLte.Treeview._jQueryInterface.call($(this), 'init');
    });
}

I do not know if this is the best solution, but it worked.

15reactions
dnzbrkyrkcommented, Apr 18, 2020

Hello,

I faced the same problem on AdminLTE 3 with React. This is how I solved it.

Create a JavaScript file with the content below :

const $ = window.$; export function loadTree() {
  const trees: any = $('[data-widget="treeview"]');
         trees.Treeview('init');

}

And on the react component which contains the menu items invoke this function inside componentDidMount()

import { loadTree } from "./js/MenuTreeHelper.js";

export default class Menu extends Component {

componentDidMount() { loadTree(); }

Read more comments on GitHub >

github_iconTop Results From Across the Web

Sidebar menu treeview not working after redirection ... - GitHub
In my case for angular 13, I have added the below codebase on my main component instead of the sidebar component. Now both...
Read more >
Angular 4 + AdminLTE. Treeview-menu isnt working
So, im working in a plataform and im using Angular 4 and AdminLTE. After logging into the dashboard, my treeview menu doesnt work....
Read more >
Sidebar menu treeview not working after redirection in Angular 4
Hi,. I'm using AdminLTE theme (2.4.0-rc) in Angular4 project. Dashboard with the sidebar menu is on url "http://host/".
Read more >
Router tutorial: tour of heroes - Angular
This tutorial provides an extensive overview of the Angular router. In this tutorial, you build upon a basic router configuration to explore features...
Read more >
How To Create a Sidebar with Icons - W3Schools
Tip: Go to our CSS Navbar Tutorial to learn more about navigation bars. Tip: If you want to create a navigation bar that...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found