首页 > 解决方案 > 如何为特定组件加载 slick-carousel 文件

问题描述

对角度如此陌生,

home.component.html

                <ul class="event-list">
                    <li>
                        <time>
                            <span class="day">21</span>
                            <span class="month">june</span>

                        </time>

                        <div class="info">
                            <h6><b>FAREWELL TO MTECH STUDENTS</b></h6>
                            <h6> Farewell to MTech students More Details
                                    </h6>
                            </div>

                        </li>

                    </ul>
                </div>
                <div>
                    <ul class="event-list">
                        <li>
                            <time>
              <span class="day">21</span>
              <span class="month">April</span>

            </time>
            </div>

            </section>

home.component.ts

import { Component, OnInit } from '@angular/core';
@Component({
  selector: 'app-home',
  templateUrl: './home.component.html',
  styleUrls: ['./home.component.css']
})
export class HomeComponent implements OnInit {

  constructor() { }

  ngOnInit() {
    $(document).on('ready', function() {

      $(".vertical-center-3").slick({
        dots: true,
        vertical: true,
        centerMode: true,
        slidesToShow: 2,
        slidesToScroll: 1,
        autoplay:true,
        autoplaySpeed:2000,
        nextArrow: null ,
        prevArrow:null
      });

      $('.center').slick({
    centerMode: true,
    centerPadding: '60px',
    slidesToShow: 5,
    autoplay:true,
    autoplaySpeed:2000,
    responsive: [
      {
        breakpoint: 768,
        settings: {
          arrows: false,
          centerMode: true,
          centerPadding: '40px',
          slidesToShow: 3
        }
      },
      {
        breakpoint: 480,
        settings: {
          arrows: false,
          centerMode: true,
          centerPadding: '40px',
          slidesToShow: 1
        }
      }
    ]
  });

    });


  }

}

这是使用 slick-slider 的组件我不熟悉在 .ts 中导入文件并调用该函数请帮帮我

标签: jqueryslick.jsangular8

解决方案


不建议在 Angular 中使用 jQuery 插件。最好尝试获取任何角度特定的轮播或 Still 如果您想使用它,请在底部的index.html文件中编写 jQuery 代码,并在main.ts文件中包含以下行。

main.ts

declare var $: any;

推荐阅读