bootstrap 4 in Angular 2 dropdown not working

后端 未结 14 1378
旧巷少年郎
旧巷少年郎 2021-02-04 08:36

I have followed the following to install bootstrap 4 into my Angular 2 project: Accepted Answer, following the first 1,2,3 and 4 steps

However when I add the following <

14条回答
  •  不要未来只要你来
    2021-02-04 09:30

    navbar.component.html

    
    

    dropdown.directive.ts

    import { Directive, HostBinding, HostListener, ElementRef } from '@angular/core';
    
        @Directive({
          selector: '[appDropdown]'
        })
        export class DropdownDirective {
          constructor(private elementRef: ElementRef) { }
    
          private dropdownParentEl = this.elementRef.nativeElement.closest('.dropdown');
    
          @HostListener('mouseenter') toggleOpen(){
            this.dropdownParentEl.querySelector(".dropdown-menu").classList.add('show');
          }
          @HostListener('mouseleave') toggleClose(){
            this.dropdownParentEl.querySelector(".dropdown-menu").classList.remove('show');
          }
    
          @HostListener('click') toogleOpen() {
              this.dropdownParentEl.querySelector(".dropdown-menu").classList.toggle('show');
          }
        }
    

提交回复
热议问题