Angular 你不会需要的

Angular 你不会需要的,angular,bootstrap-4,Angular,Bootstrap 4,干杯,并享受使用它的乐趣。我对这个问题有点困惑,我是否正确理解了,您想要类似于显示树结构的下拉菜单的东西?下拉列表中的每个元素在当前菜单中打开另一个下拉列表?或者,当鼠标悬停时,导航栏中是否有打开另一个菜单的一般想法?@hGen感谢您的回答。很抱歉造成混淆。@hGen我想要一个下拉列表,其中每个元素在当前菜单中打开另一个下拉列表。非常感谢:)它真的很有帮助 <span ngbDropdown #myDrop="ngbDropdown" class="dropdown-wrapper">

干杯,并享受使用它的乐趣。

我对这个问题有点困惑,我是否正确理解了,您想要类似于显示树结构的下拉菜单的东西?下拉列表中的每个元素在当前菜单中打开另一个下拉列表?或者,当鼠标悬停时,导航栏中是否有打开另一个菜单的一般想法?@hGen感谢您的回答。很抱歉造成混淆。@hGen我想要一个下拉列表,其中每个元素在当前菜单中打开另一个下拉列表。非常感谢:)它真的很有帮助
<span ngbDropdown #myDrop="ngbDropdown" class="dropdown-wrapper">
        <img class="hidden-md-up" src="More Menu.svg" aria-hidden="true" ngbDropdownToggle/>
        <span ngbDropdownMenu aria-labelledby="dropdownBasic1">
          <p class="dropdown-label"><img src="selectall.svg" class="dropdown-item">Select All</p>
          <p class="dropdown-label"><img src="filter.svg" class="dropdown-item">Filter</p>
          <p class="dropdown-label"><img src="export.svg" class="dropdown-item">Export</p>
          <p class="dropdown-label"><img src="edit.svg" class="dropdown-item">Bulk Edit</p>
          <p class="dropdown-label"><img src="sort.svg" class="dropdown-item">Sort</p>
          <p class="dropdown-label"><img src="tileview.svg" class="dropdown-item" (click)="openSubMenu()">
            Tile View
          </p>
        </span>
      </span>
structure = [
  {
    title: "foo",
    link: "/foo",
    children: [
      {
        title: "bar",
        link: "/bar",
        children: []
      }
    ]
  },
  {
    title: "baz",
    link: "/baz",
    children: []
  }
];
<ul class="tree-root-list">
    <app-tree-node *ngFor="let item of structure"
                   [current]="item">
    </app-tree-node>
</ul>
<li class="node-item">

    // this function will trigger the final action triggered when a node is selected
    // if there are subnodes open the list, else link to the respective page, route, etc..
    <p #title (click)="nodeSelected()">

        <span class="icon-container">
            <span> 
                //optional icon 
            </span>
        </span>

        <span class="node-title">
            // optional text
            {{title}}
        </span>

    </p>

    <ul class="child-list"
        *ngIf="hasChildElements()"
        [collapse]="children_collapsed"
        (collapsed)="collapsed($event)"
        (expanded)="expanded($event)">

        // thats the part the structure object comes in handy,
        // since you don't need to add several node tags
        // you'll just need to add or remove elements in the structure
        // variable
        <app-tree-node *ngFor="let child of current.children"
                       [current]="child">
        </app-tree-node>
    </ul>

</li>
@Component({
  selector   : 'app-tree-node',
  templateUrl: './tree-node.component.html',
  styleUrls  : ['tree-node.component.scss']
})
export class TreeNodeComponent implements OnInit {

  // inputs
  @Input() current: any;
  @Input() is_root: boolean;

  // ...

  // public members
  public children_collapsed = true;

  // view nodes
  // can be useful when you want to highlight certain nodes depending on specific actions
  // though not a requirement for the main task
  @ViewChildren(TreeNodeComponent) child_nodes: QueryList<TreeNodeComponent>;

  /**
   * c'tor ...
   */


  /**
   * click event when node is selected
   */
  public nodeSelected(): void {

    // if there are child elements
    if (this.hasChildElements()) {

      // change collapsed state
      this.children_collapsed = !this.children_collapsed;

    } else {

      // probably route to somewhere, do whatever you want to do with no children present here
    }

  }

  /**
   * check whether there are children
   */
  public hasChildElements(): boolean {
    return this.current.hasOwnProperty("children");
  }


  /**
   * fires if div is collapsed
   * @param event
   */
  public collapsed(event: any): void {
    // change icon
    // needed this to give a visual feedback whether the folder is opened or closed
    if (this.hasChildElements()) {
      this.folder_icon.nativeElement.className = "glyphicon glyphicon-folder-close";
    }
  }


  /**
   * fires if div is expanded
   * @param event
   */
  public expanded(event: any): void {
    if (this.hasChildElements()) {
      this.folder_icon.nativeElement.className = "glyphicon glyphicon-folder-open";
    }
  }

}