通知关于更改Angular2的指令

时间:2016-07-20 11:58:29

标签: typescript angular angular2-directives angular2-components

我有问题,帮忙解决 我有一个带模板的组件

ul(slider)
    li(*ngFor="let car of getRecentCars()")
        car-poster(bcg="{{car.recentBackgroundUrl}}",  image="{{car.indexImage}}")

指令滑块

@Directive({
    selector: '[slider]'
})
export class sliderDirective{
    private el: HTMLElement;

    constructor(@Inject(ElementRef) elementRef: ElementRef) {
        this.el = elementRef.nativeElement;
        let _this = this;
        setTimeout(function(){
            $(_this.el).slick({
                infinite: false,
                slidesToShow: 1,
                slidesToScroll: 1
            });
        }, 0);


    }

}

但该指令是在组件中的数据之前触发的 怎么做才有可能推迟启动指令渲染组件

1 个答案:

答案 0 :(得分:0)

您可以利用col2 + col3之类的组件/指令生命周期挂钩:

以下是一个示例:

ngAfterViewChecked

有关详细信息,请参阅此文档: