首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在角8中实现Swiper

在角8中实现Swiper
EN

Stack Overflow用户
提问于 2019-12-27 09:33:52
回答 1查看 21.4K关注 0票数 2

我正试图在我的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

代码语言:javascript
复制
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

代码语言:javascript
复制
<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>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-12-27 09:56:32

我们用斯威珀在我们的角度应用。

我们是如何集成它的:有一个npm软件包,专门用于角:https://www.npmjs.com/package/ngx-swiper-wrapper

所以你只需要安装这个软件包:

npm i ngx-swiper-wrapper

然后,导入模块(我们已经将其放入SharedModule并导出它,以便可以从任何地方访问它):

代码语言:javascript
复制
imports: [
    // more imports here
    SwiperModule
]

然后您可以在组件中使用它,如下所示:

代码语言:javascript
复制
<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>

作为一个配置,您可以拥有如下内容:

代码语言:javascript
复制
    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文件中包含任何样式。他们都跟你进口的那个模块一起来的。

票数 7
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59498661

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档