Angular 2,使用Jquery操作引导

Angular 2,使用Jquery操作引导,jquery,angularjs,twitter-bootstrap,angular2-directives,Jquery,Angularjs,Twitter Bootstrap,Angular2 Directives,我是NG2的新手,我正在尝试添加幻灯片向上/向下效果的默认引导4下拉组件 引导下拉组件有两个Jquery侦听器$(el).on('show.bs.dropdown')和$(el).on('hide.bs.dropdown')。所以我创建了一个指令来添加这种效果: import { Directive, OnInit, AfterViewChecked, ElementRef, Input } from '@angular/core'; import * as $ from 'jquery';

我是NG2的新手,我正在尝试添加幻灯片向上/向下效果的默认引导4下拉组件

引导下拉组件有两个Jquery侦听器
$(el).on('show.bs.dropdown')
$(el).on('hide.bs.dropdown')
。所以我创建了一个指令来添加这种效果:

import { Directive, OnInit, AfterViewChecked, ElementRef, Input } from '@angular/core';
import * as $ from 'jquery';

@Directive({
  selector: '[appDropDownAnimate]'
})
export class DropDownAnimateDirective implements AfterViewChecked {
  @Input()
  appDropDownAnimate: boolean;

  private el = this.ElementRef.nativeElement;
  constructor(private ElementRef: ElementRef) {
  }

  ngAfterViewChecked () {
    const el = this.el;
      debugger;
      $(el).on('show.bs.dropdown',
      (cb) => {
        $(el).find('.dropdown-menu').first().stop(true, true).slideDown('fast');
      });
     $(el).on('hide.bs.dropdown',
     (cb) => {
        $(el).find('.dropdown-menu').first().stop(true, true).slideUp('fast');
     });
  }
}
虽然未触发任何错误,但不会产生任何影响:/。但是在调试器点,当浏览器处于冻结状态时,如果我在控制台复制/粘贴代码,它确实可以工作。所以我真的很沮丧,因为我很确定我的代码是正确的,但我不明白为什么它在代码定义中不起作用

PS:我试着在setTimeout上包装它,看看它是否是一个DOM渲染问题,但也不起作用。我也试过所有NG2救生钩

如果有人能帮我解决这个问题,并向我解释这种奇怪行为的原因,我将不胜感激

规格:

引导程序4,Angular 4.3,JQuery 3.2.1

我想从jquery中将*导入为$和app.module.ts不在指令中

即使在那里,仍然很奇怪,在module.ts或my directive.ts中导入jquery应该不是一个问题。无论如何,我当时应该能够使用user$方法。

哦,天哪

我想从jquery中将*导入为$和app.module.ts不在指令中


即使在那里,仍然很奇怪,在module.ts或my directive.ts中导入jquery应该不是一个问题。无论如何,我当时应该能够使用user$方法。

除了当前的错误之外,您还说了所有的话!你能发布控制台异常吗?您还应该使用AfterViewInit而不是AfterViewChecked!没有错误,幻灯片就是不起作用:/。但是如果我复制/粘贴
$(el).on('show.bs.dropdown',(cb)=>{$(el).find('dropdown menu').first().stop(true,true).slideDown('fast');})$(el).on('hide.bs.dropdown',(cb)=>{$(el).find('.dropdown menu').first().stop(true,true).slideUp('fast');})在调试点期间,当浏览器冻结时。它将在视图完全加载后开始工作,然后您应该能够操作DOM。我也尝试了AfterViewInit和所有其他XD。仍然不工作除了你现在犯的错误,你什么都说了!你能发布控制台异常吗?您还应该使用AfterViewInit而不是AfterViewChecked!没有错误,幻灯片就是不起作用:/。但是如果我复制/粘贴
$(el).on('show.bs.dropdown',(cb)=>{$(el).find('dropdown menu').first().stop(true,true).slideDown('fast');})$(el).on('hide.bs.dropdown',(cb)=>{$(el).find('.dropdown menu').first().stop(true,true).slideUp('fast');})在调试点期间,当浏览器冻结时。它将在视图完全加载后开始工作,然后您应该能够操作DOM。我也尝试了AfterViewInit和所有其他XD。仍然不起作用