Materializecss angular 5 dropdown content dynamic generation throws error

ぐ巨炮叔叔 提交于 2021-02-18 19:22:48

问题


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 generation. It throws this error: ERROR TypeError: Cannot set property 'tabIndex' of null

html

<ul id="content-{{labSystem.system.name}}" 
    class="dropdown-content" *ngFor="let labSystem of nodeLabSystems">
    <li>
      <a href="#!">one</a>
    </li>
  </ul>

<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>

typescript

  open(dropdown): void {
    const elem = document.getElementById(dropdown);
    const instance = M.Dropdown.init(elem, {constrainWidth: true});
    instance.open();
  }

来源:https://stackoverflow.com/questions/50567845/materializecss-angular-5-dropdown-content-dynamic-generation-throws-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!