materialize
materialize copied to clipboard
Dynamic dropdown-content generation with Angular5 throw a tabIndex null exception
When I generate dynamic content with different dropdowns the dropdown throws an error. If I do not generate dynamic dropdown content it works, the problem is with that generatiaon
Expected Behavior
Open a drop down
Current Behavior
It throws an error: Cannot set property 'tabIndex' of null
Steps to Reproduce (for bugs)
HTML
<div class="col s12 m12 l12 xl12 blue-grey lighten-1">
<div id="instrumentStatus">
<span class="right" *ngFor="let labSystem of nodeLabSystems">
<a class="btn btn-flat dropdown-trigger" data-target="content-{{labSystem.system.name}}" id="{{labSystem.system.name}}"
(click)="open(labSystem.system.name)">{{labSystem.system.name}}</a>
</span>
</div>
</div>
<ul id="content-{{labSystem.system.name}}" class="dropdown-content" *ngFor="let labSystem of nodeLabSystems">
<li>
<a href="#!">one</a>
</li>
</ul>
Typescript
open(dropdown): void {
const elem = document.getElementById(dropdown);
const instance = M.Dropdown.init(elem, {constrainWidth: true});
instance.open();
}
Context
I want to have a dropdown with revelant information about my items.
Your Environment
- Version used: 1.0.0-rc.1
- Browser Name and version: chrome 63
- Operating System and version (desktop or mobile): ubuntu 16.04
- Link to your project (if appropriate):
Hi,
I had the same problem. In my case the data-target was not matching with the id of target element. You may check also if the dropdown is initializing after your html was already rendered.
The same error appears when you call the Autocomplete plugin:
const autocomplete = M.Autocomplete.init(searchForm.querySelectorAll('input'));
<div class="search-bar-container">
<form id="search-bar" action="#">
<input name="q" type="search" class="autocomplete" required value="">
<button type="submit" class="waves-effect tooltipped">
<i class="center material-icons">search</i>
</button>
</form>
</div>