首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在角度上使用Swiperjs?

如何在角度上使用Swiperjs?
EN

Stack Overflow用户
提问于 2020-04-03 22:29:50
回答 1查看 1.2K关注 0票数 0

我知道有一个模块,但我想通过它的CDN在我的角度应用程序中使用Swiper。

我在head of my index.html中包含了这些脚本。

然后,在我想要使用它的组件中,我已经将其作为如下内容进行了删除:

代码语言:javascript
复制
  import { Component, OnInit } from '@angular/core';
import { MenuService } from '../_services/menu.service';
import { ContentfulService } from '../_services/contentful.service';
import { Entry } from 'contentful';
declare let Swiper: any;

/* and initialised in the constructor*/

  constructor(
    public menu: MenuService,
    private contentfulService: ContentfulService
  ) {
    new Swiper('.swiper-container', {
      // Optional parameters
      direction: 'vertical',
      loop: true,
    });
  }

我没有收到任何错误,但它根本不起作用。例如,箭头也被加载,但是没有绑定到它们的事件。任何帮助都是非常感谢的。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-04-04 09:02:40

只需更改index.html https://stackblitz.com/edit/angular-d21ywf中的脚本和css链接即可。

代码语言:javascript
复制
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/Swiper/3.4.2/css/swiper.min.css">
  <script src="https://cdnjs.cloudflare.com/ajax/libs/Swiper/3.4.2/js/swiper.min.js"></script>

然后带着你的酒杯

代码语言:javascript
复制
import { Component ,AfterViewInit} from '@angular/core';
declare let Swiper: any;


@Component({
  selector: 'my-app',
  templateUrl: './app.component.html',
  styleUrls: [ './app.component.css' ]
})
export class AppComponent  implements AfterViewInit {
  name = 'Angular';

  constructor() {

  }
  ngAfterViewInit() {
    new Swiper('.swiper-container', {
       pagination: '.swiper-pagination',
        paginationClickable: true,
        nextButton: '.swiper-button-next',
        prevButton: '.swiper-button-prev',
        autoplay: 3000,
        spaceBetween: 30,
        direction: 'vertical',
        loop: true
    });
  }
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61021368

复制
相关文章

相似问题

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