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

[bug?] Menus will not display on dynamic content #4243

Closed
efortes opened this issue Apr 1, 2016 · 7 comments
Closed

[bug?] Menus will not display on dynamic content #4243

efortes opened this issue Apr 1, 2016 · 7 comments

Comments

@efortes
Copy link

efortes commented Apr 1, 2016

The menu items won't display if the content is loaded from the backend (dynamic data)
My code
<button id="menu-speed" class="mdl-button mdl-js-button mdl-button--icon"> <i class="material-icons">more_vert</i> </button> <ul class="mdl-menu mdl-js-menu" for="menu-speed"> <li class="mdl-menu__item">Fast</li> <li class="mdl-menu__item">Medium</li> <li class="mdl-menu__item">Slow</li> </ul>

In non dynamic content the current div is added:

<div class="mdl-menu__outline mdl-menu--bottom-right" style="width: 148.313px; height: 208px;"></div>

Am i doing something wrong or is this a bug?

@efortes
Copy link
Author

efortes commented Apr 1, 2016

I am using angular 2

@efortes
Copy link
Author

efortes commented Apr 1, 2016

`

<script> var button = document.createElement('button'); var textNode = document.createTextNode('Click Me!'); button.appendChild(textNode); button.className = 'mdl-button mdl-js-button mdl-js-ripple-effect'; componentHandler.upgradeElement(button); document.getElementById('container').appendChild(button); </script>`

You need to use the componentHandler to fix this problem

@tjoskar
Copy link

tjoskar commented Apr 3, 2016

Calling .upgradeAllRegistered() after the template has rendered should do the trick.

Eg. in angular 2:

ngAfterViewInit() {
    window.componentHandler.upgradeAllRegistered();
}

@efortes
Copy link
Author

efortes commented Apr 3, 2016

Ahh great answer tjoskar. I will try that

@efortes
Copy link
Author

efortes commented Apr 5, 2016

For the typescript users. You might want to declare the window object on top.

declare var window:any;

@maiakaat
Copy link

I seem to have seen possible issues when using Angular 2, but I'm too much of a beginner to add anything meaningful at this stage.

@Garbee
Copy link
Collaborator

Garbee commented May 25, 2016

Please use StackOverflow for support and integration assistance. This tracker is only for problems with the code provided by Material Design Lite.

Thank you.

@Garbee Garbee closed this as completed May 25, 2016
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

4 participants