我在我的角2应用程序中使用了引导数据器(http://bootstrap-datepicker.readthedocs.io/en/latest/index.html),并且在初始化方面有一些问题。
在我的组件中使用下面的内容是有效的,但不是很好
ngAfterViewInit(): void {
setTimeout(function() {
$('.date').each(function() {
console.log($(this));
$(this).datepicker({
format: 'dd.mm.yyyy',
autoclose: true,
calendarWeeks: true,
language: 'de-DE',
todayHighlight: true
});
});
}, 1000)
}有没有一种不需要1秒的脏超时的方法来实现这个工作呢?如果没有超时,则jQuery选择器不会返回任何内容,控制台中也没有输出。
发布于 2017-08-17 08:58:20
问题是数据报警器在*ngIf指令中。
解决方案是将@ViewChildren与QueryList一起使用,并在查询列表更改后进行初始化(订阅更改事件)
https://stackoverflow.com/questions/45211602
复制相似问题