问题是-我有另一个例子的光滑滑块和事情变得混乱。
如何在构造函数中为私有el变量设置变量:
例如-我如何使用jquery直接引用一个元素,而不是像在这里那样在整个树中搜索?
jQuery(this.el.nativeElement).variable.slick({..
import { Component, ElementRef, ViewChild, HostListener, Input, Renderer, OnInit } from '@angular/core';
import { WindowRefService } from 'app/core/window-ref.provider';
declare var jQuery: any;
@Component({
moduleId: module.id,
selector: 'app-preview',
templateUrl: 'app-preview.component.html'
})
export class AppPreviewComponent implements OnInit {
constructor(private el: ElementRef) { }
ngOnInit() {
jQuery(this.el.nativeElement).slick({
infinite: false,
arrows: true,
variableWidth: true,
centerMode: true,
dots: false,
focusOnSelect: true,
cssEase: 'ease-in-out'
});
}
}发布于 2017-04-11 13:23:05
我不完全确定您的jQuery.slick()插件是什么,但在Angular2部分:
您可能需要考虑将其放入ngAfterViewInit()方法中(不要忘记将其添加到implements部件中),因为这是在加载了implements的生命周期中触发的。
查找Angular2的Angular2部分可能很有趣。看起来有点像这样:
ViewChild('some-id') variableName: ElementRef
在HTML中:
<blabla #some-id></blabla>
然后,您就可以在控制器中访问this.variableName,您可以将其他函数(如jQuery插件)串到其中。
https://stackoverflow.com/questions/43347136
复制相似问题