MetisMenu Angular 2 - not working on first load
See original GitHub issuemetisMenu not working on initial or first load. After refresh it works fine,
My app.component.ts looks like this,
/// <reference path="../typings/globals/jquery/index.d.ts" />;
import { Router } from '@angular/router';
import { Component, OnInit, AfterViewInit } from '@angular/core';
@Component({
moduleId: module.id,
selector: 'app-tag',
templateUrl: 'app.component.html',
})
export class AppComponent implements OnInit, AfterViewInit {
constructor(private _router: Router) {
}
ngOnInit(): void {
}
ngAfterViewInit() {
(<any>$('#side-menu')).metisMenu();
}
}
My menu items looks like this,
<li>
<a href="#"><i class="fa fa-volume-control-phone fa-fw"></i> Heading1<span class="fa arrow"></span></a>
<ul class="nav nav-second-level">
<li><a [routerLink]="['/h1c1']">H1-Child1</a></li>
</ul>
</li>
<li>
<a href="#"><i class="fa fa-users fa-fw"></i> Heading 2<span class="fa arrow"></span></a>
<ul class="nav nav-second-level">
<li><a [routerLink]="['/h2c1']">H2-Child1</a></li>
</ul>
</li>
I’m not getting any error. All the menu items are expanded by default on the first load. When I click on the head item, the page gets refreshed and all the menu items are collapsed and everything works fine from then on…
Issue Analytics
- State:
- Created 7 years ago
- Comments:9
Top Results From Across the Web
jquery metismenu not working loading data async with ...
I want to load menu elements from Database and I'm using AngujarJS controller to get the JSON with menu elements. Here is AngularJSController...
Read more >@metismenu/angular - npm
Start using @metismenu/angular in your project by running `npm i @metismenu/angular`. There are no other projects in the npm registry using ...
Read more >DevTools failed to load source map - Microsoft Q&A
Dear,. 48h ago, my Sharepoint online apps suddenly stopped working. I see this error in the browser console: DevTools failed to load source...
Read more >metisMenu - Bountysource
I am using MetisMenu in an angular app, and ran into the problem described ... I have tried the suggestion of first disposing...
Read more >3 Ways to Solve jQuery - Uncaught ReferenceError: $ is not ...
If you are using jQuery, Angular JS, or plain old JavaScript and getting ... is loaded and getting this error it means your...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This worked for me
first declare jquery after your imports declare var jQuery:any;
replace this: (<any>$(‘#side-menu’)).metisMenu();
with this: jQuery(‘#side-menu’).metisMenu();
@BlankHrt - Me neither. In the end I built a vanilla Angular 4 component:
Dependencies:
Component: