【问题标题】:Property 'kendoGrid' does not exist on type 'JQuery<HTMLElement>'JQuery<HTMLElement> 类型上不存在属性'kendoGrid'
【发布时间】:2017-07-13 07:28:48
【问题描述】:

我正在使用 VSCode 编辑器进行我的 Angular 项目开发。 VSCode 智能感知与 @typings/kendo-ui 一起工作得很好。但是,由于错误,Webpack 编译失败。

错误:

“类型“JQuery”上不存在属性“kendoGrid”

这个错误对于所有剑道组件都是一样的

我正在为这个项目使用最新的 Angular CLI。

【问题讨论】:

    标签: jquery angularjs kendo-ui webpack angular-cli


    【解决方案1】:

    不确定您是否已经得到答案,但 kendoGrid 依赖于 jQuery。除了安装 jQuery 和 kendoGrid 文件之外,您还应该在您使用的任何组件中的 ngAfterViewInit lifecyle 挂钩中添加您的 kendoGrid 代码,如下所示:

      ngAfterViewInit(){
          $(document).ready(function(){
                  // code to execute
                  });
    }
    

    同时添加declare var $:any; 它声明了任何类型的 jQuery 变量。假设您在模块文件中添加了import * as $ from 'jquery'

    【讨论】:

    • 我的项目中有 jquery 类型。所以,我得到了重复的 $ 声明错误。
    【解决方案2】:

    试试这个

    (<any>$("#grid")).kendoGrid()
    

    【讨论】:

    • 我会用上面的代码失去智能感知。否则我会将 $ 声明为单独的常量,例如 declare const $: any 这也有效。但是,问题是我想要智能感知并能够构建 Angular 项目
    【解决方案3】:

    如果您使用的是 Angular CLI,则 component.ts 所需的唯一导入语句是

    declare var $: any;
    

    而不是import * as $ from 'jquery'declare var $:any;

      ngAfterViewInit(){
      $(document).ready(function(){
              // code to execute
              });
    

    }

    【讨论】:

      猜你喜欢
      • 2018-03-08
      • 2020-01-17
      • 1970-01-01
      • 1970-01-01
      • 2018-06-21
      • 2020-02-16
      • 2020-04-08
      • 1970-01-01
      • 2022-01-13
      相关资源
      最近更新 更多