我正试图在我的8应用程序:https://swiperjs.com/get-started/中实现Swiper。
我在资产文件夹中创建了一个javascript文件,并将其包含到我的angular.json中。
此外,我还在我的中包含了,并运行了命令npm install @types/swiper。
,但是,我得到了错误:
[ts] Module '"../node_modules/@types/swiper/index has no exported member 'Swiper'
当它清楚的时候。我不知道我哪里出了问题。
card-swipe.component.ts
import { SwiperModule, SwiperConfigInterface } from 'ngx-swiper-wrapper';
@Component({
selector: 'app-card-swipe',
templateUrl: './card-swipe.component.html',
styleUrls: ['./card-swipe.component.css']
})
export class CardSwipeComponent implements OnInit {
constructor() { }
something;
index;
config: SwiperConfigInterface = {
a11y: true,
direction: 'horizontal',
slidesPerView: 3,
slideToClickedSlide: true,
mousewheel: true,
scrollbar: false,
watchSlidesProgress: true,
navigation: true,
keyboard: true,
pagination: false,
centeredSlides: true,
loop: true,
roundLengths: true,
slidesOffsetBefore: 100,
slidesOffsetAfter: 100,
spaceBetween: 50,
breakpoints: {
// when window width is >= 320px
320: {
slidesPerView: 1
}
}
};
ngOnInit() {}
}card-swipe.component.html
<p>Hi this works</p>
<!-- Slider main container -->
<swiper fxFlex="auto" [config]="config" (indexChange)="onIndexChange($event)">
<div *ngFor="let step of something; let index = index" class="swiper-slide cursor-pointer">
<div fxLayout="column" fxLayoutAlign="center center" fxFlexFill class="mx-2">
<p>hi</p>
<h1>hello</h1>
</div>
</div>
</swiper>发布于 2019-12-27 09:56:32
我们用斯威珀在我们的角度应用。
我们是如何集成它的:有一个npm软件包,专门用于角:https://www.npmjs.com/package/ngx-swiper-wrapper
所以你只需要安装这个软件包:
npm i ngx-swiper-wrapper
然后,导入模块(我们已经将其放入SharedModule并导出它,以便可以从任何地方访问它):
imports: [
// more imports here
SwiperModule
]然后您可以在组件中使用它,如下所示:
<swiper fxFlex="auto" [config]="config" (indexChange)="onIndexChange($event)">
<div *ngFor="let step of something; let index = index" class="swiper-slide cursor-pointer">
<div fxLayout="column" fxLayoutAlign="center center" fxFlexFill class="mx-2">
<!-- Your content goes here -->
</div>
</div>
</swiper>作为一个配置,您可以拥有如下内容:
config: SwiperConfigInterface = {
a11y: true,
direction: 'horizontal',
slidesPerView: 3,
slideToClickedSlide: true,
mousewheel: true,
scrollbar: false,
watchSlidesProgress: true,
navigation: true,
keyboard: true,
pagination: false,
centeredSlides: true,
loop: true,
roundLengths: true,
slidesOffsetBefore: 100,
slidesOffsetAfter: 100,
spaceBetween: 50,
breakpoints: {
// when window width is >= 320px
320: {
slidesPerView: 1
}
}
};不需要在angular.json文件中包含任何样式。他们都跟你进口的那个模块一起来的。
https://stackoverflow.com/questions/59498661
复制相似问题