【发布时间】:2017-09-07 06:32:56
【问题描述】:
我正在尝试将 owlcarousel 2 与 angular 4 一起使用。我有以下设置:
.angular-cli.json:
"scripts": ["../node_modules/jquery/dist/jquery.js",
"../node_modules/tether/dist/js/tether.js",
"../node_modules/bootstrap/dist/js/bootstrap.js",
"../node_modules/owl.carousel/dist/owl.carousel.js"
],
offers-component.ts:
import { Component, AfterViewInit } from '@angular/core';
declare var $: any;
@Component({
selector: 'home-offers-container',
templateUrl: '../templates/home-offers-container.template.html',
styleUrls: ['../css/home-offers-container.component.css']
})
export class HomeOffersContainerComponent implements AfterViewInit {
ngAfterViewInit() {
$('.owl-carousel').owlCarousel();
}
}
template.html
<div class="row">
<div class="container">
<home-offers class="owl-carousel"></home-offers>
</div>
</div>
我收到一个错误ERROR TypeError: $(...).owlCarousel is not a function。我不明白为什么会弹出这个错误。我已经按原样订购了脚本 - 首先是 jquery,然后是 owlcarousel。此外 typescriptp 不会在 jQuery 上给出任何错误。我错过了什么/没有正确加载owlCarousel?
我必须在 app.module.ts 中导入 jQuery / owlCarousel 吗?如果是,有什么建议吗?
【问题讨论】:
标签: jquery angular owl-carousel-2