Angular 6错误TS2339:类型“ JQueryStatic”上不存在属性“ scrollUp”

时间:2019-05-09 11:12:51

标签: jquery angular typescript angular6 angular-template

我正在Angular 6中使用jQuery。我已经安装了以下步骤:

npm install jquery
npm install --save @types/jquery

我已经在我的angular.json中添加了jQuery,如下所示:

"./node_modules/jquery/dist/jquery.min.js",
"./node_modules/bootstrap/dist/js/bootstrap.min.js",
"src/assets/js/plugins.js"

plugins.js具有jQuery的自定义功能。在我的header.component.ts文件中,当我使用来自plugins.js的以下功能之一时,会出现以下错误:

ERROR in src/app/includes/header/header.component.ts(31,9): error TS2339: Property 'scrollUp' does not exist on type 'JQueryStatic'.

header.component.ts文件看起来像这样:

import * as $ from "jquery";

declare const meanmenu: any;
declare const scrollUp: any;
 ngOnInit() {
  $.scrollUp({
        scrollText: '<i class="fa fa-angle-up"></i>',
        easingType: 'linear',
        scrollSpeed: 900,
        animation: 'slide'
      });
}

1 个答案:

答案 0 :(得分:0)

interface jQueryStatic {
  scrollUp: any;
}

($ as any).scrollUp({
        scrollText: '<i class="fa fa-angle-up"></i>',
        easingType: 'linear',
        scrollSpeed: 900,
        animation: 'slide'
      });

为我工作...