简体   繁体   English

在角度6中使用slick.js时出错

[英]error using slick.js in angular 6

I am trying to use slick.js a carousel framework in angular. 我试图在角度使用slick.js轮播框架。

I tried `npm install slick --save' and adding the downloaded files in my scripts and styles json objects. 我尝试了`npm install slick --save'并将下载的文件添加到我的脚本和样式json对象中。

that didn't work so then I imported the css and js in my angular index.html file: 那没有用,所以我在我的角度index.html文件中导入了css和js:

<link rel="stylesheet" type="text/css" href="slick/slick.css"/>
  <link rel="stylesheet" type="text/css" href="slick/slick-theme.css"/>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
  <app-root></app-root>
  <script type="text/javascript" src="//code.jquery.com/jquery-1.11.0.min.js"></script>
  <script type="text/javascript" src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
  <script type="text/javascript" src="slick/slick.min.js"></script>
</body>

then I install jquery typings by doing 然后我通过安装jquery类型

npm install typings/jquery --save-dev

then in the relevant ts file I use slick and import jquery 然后在相关的ts文件中,我使用slick并导入jquery

import * as jQuery from 'jquery';
...

ngOnInit(){
jQuery<any>('cuisinecarousel').slick({
      centerMode: true,
      centerPadding: '60px',
      slidesToShow: 3,
      responsive: [
        {
          breakpoint: 768,
          settings: {
            arrows: false,
            centerMode: true,
            centerPadding: '40px',
            slidesToShow: 3
          }
        },
        {
          breakpoint: 480,
          settings: {
            arrows: false,
            centerMode: true,
            centerPadding: '40px',
            slidesToShow: 1
          }
        }
      ]

    });
...
}

but then I get this error: 但是然后我得到这个错误:

ERROR in mainroot/venuepage/venuepage.component.ts(451,36): error TS2551: Property 'slick' does not exist on type 'JQuery<any>'. Did you mean 'click'?

anyone have similar issues and how to fix? 任何人都有类似的问题,以及如何解决?

Gratzi 格拉齐

I found this: Going to try it and see if it fixes 我发现了这一点:尝试一下,看看是否可以解决

https://github.com/devmark/ngx-slick https://github.com/devmark/ngx-slick

try using: 尝试使用:

declare var $: any;

instead of: 代替:

import * as jQuery from 'jquery';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM