我在Angular 7中使用Owl旋转木马 . 首先我安装With
npm install ngx-owl-carousel owl.carousel jquery --save
然后加
"scripts": ["./node_modules/jquery/dist/jquery.min.js",
"./node_modules/owl.carousel/dist/owl.carousel.min.js"]
在angular.json文件中添加
import { OwlModule } from 'ngx-owl-carousel';
imports: [
BrowserModule,
OwlModule
]
在app.module.ts文件然后我使用
public ngOnInit()
{
/*----------------------------
Slideshow
------------------------------ */
$('.slideshow').owlCarousel({
items: 6,
autoPlay: 3000,
singleItem: true,
navigation: true,
navigationText: ['<i class="fa fa-chevron-left"></i>', '<i class="fa fa-chevron-right"></i>'],
pagination: true
});
}
在app.component.ts文件中,但我有错误
core.js:14576 ERROR TypeError:jquery__WEBPACK_IMPORTED_MODULE_2__(...) . owlCarousel不是函数
我在哪里弄错了?请帮我 . 谢谢 .
1 回答
导入OwlModule后,您可以在Angular模板中使用其导出的组件,如下所示(示例来自github repo):