大佬教程收集整理的这篇文章主要介绍了在 Angular 中设置 Tiny-Slider,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
嗨,我正在尝试在我的 Angular 9 项目中使用 Tiny-slIDer。我正在遵循 this 指南。
我的组件如下所示:
import { tns } from "../../../../../node_modules/Tiny-slIDer/src/Tiny-slIDer"
...
ngOnInit(): voID {
tns({
container: '.my-slIDer',items: 3,slIDeBy: 'page',autoplay: true
});
}
HTML:
<div class="my-slIDer">
<div>1</div>
<div>2</div>
<div>3</div>
</div>
我收到这些错误:
那么显然它找不到dom元素?知道如何让它在 Angular 下工作。
在 ngOnInit()
Lifecycle Hook 中,实际的 html DOM 元素尚不可用。您需要改用 ngAfterViewInit()
。只需在您的组件中实现 AfterViewInit
接口。像这样:
export class ExampleComponent implements AfterViewInit{
ngAfterViewInit(){
tns(...)
}
}
以上是大佬教程为你收集整理的在 Angular 中设置 Tiny-Slider全部内容,希望文章能够帮你解决在 Angular 中设置 Tiny-Slider所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。