0
我在angular2新手,我現在想用貓頭鷹旋轉木馬如何在Angular2中使用owlcarousel?
,我發現這個教程,但它給了我很多的錯誤,我可以找出什麼是一個問題,所以有人可以解釋again.thanks
How to use owl-carousel in Angular2?
這是我的代碼
首頁組件的HTML
<owl-carousel [options]="{navigation: false, pagination: true, rewindNav : false}">
<div *ngFor="let img of images">
<img src="http://lorempixel.com/400/200/{{img}}"/>
</div>
</owl-carousel>
首頁組件TS
import { Component, OnInit } from '@angular/core';
import { OwlCarousel } from '../owl-carousel.component';
@Component({
selector: 'app-home',
templateUrl: './home.component.html',
styleUrls: ['./home.component.css']
})
export class HomeComponent implements OnInit {
constructor() { }
ngOnInit() {
}
images: Array<string> = ['sports', 'abstract', 'people', 'transport', 'city', 'technics', 'nightlife', 'animals'];
}
我還進口在app.module.ts
owl.component.ts
import { Component, Input, ElementRef, HostBinding } from '@angular/core';
import * as $ from 'jquery';
import 'owl-carousel';
@Component({
selector: 'owl-carousel',
template: `<ng-content></ng-content>`
})
export class OwlCarousel {
@HostBinding('class') defaultClass = 'owl-carousel';
@Input() options: object;
$owlElement: any;
defaultOptions: any = {};
constructor(private el: ElementRef) {}
ngAfterViewInit() {
// use default - empty
// for (var key in this.options) {
// this.defaultOptions[key] = this.options[key];
// }
this.$owlElement = $(this.el.nativeElement).owlCarousel(this.defaultOptions);
}
ngOnDestroy() {
this.$owlElement.data('owlCarousel').destroy();
this.$owlElement = null;
}
}
錯誤
Cannot find module 'jquery'. Module not found: Error: Can't resolve 'owl-carousel'