错误 TS2339:“JQuery"类型上不存在属性“模态" [英] error TS2339: Property 'modal' does not exist on type 'JQuery'

查看:29
本文介绍了错误 TS2339:“JQuery"类型上不存在属性“模态"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将 Typescript 与 AngularJS 一起使用.我在使用 jQuery 库的类型化定义时遇到了模态问题.我收到以下错误:'错误 TS2339:类型'JQuery' 上不存在属性'modal'.'

I'm using Typescript with AngularJS. I have a problem with modals using typed definition of jQuery library. I get the following error: 'error TS2339: Property 'modal' does not exist on type 'JQuery'.'

版本:jQuery 库,版本 1.10.x/2.0.x定义:https://github.com/borisyankov/DefinitelyTyped

Version: jQuery library, version 1.10.x / 2.0.x Definitions: https://github.com/borisyankov/DefinitelyTyped

代码

$scope.delete = function (id) {
  Photo.get({id: id}, function(result) {
     $scope.photo = result;
     $('#deletePhotoConfirmation').modal('show');// error line 
  });
};

我在 angular.d.ts

<reference path="../jquery/jquery.d.ts" />

我的全球供应商参考文件如下所示:

and my global vendor reference file looks like:

<reference path='../vendor/types/angular/angular.d.ts' />
<reference path='../vendor/types/angular/angular-mocks.d.ts' />
<reference path='../vendor/types/jasmine/jasmine.d.ts' />

推荐答案

使用较新版本的 typescript (>v2 我相信):

with newer versions of typescript (>v2 i believe):

npm install -D @types/bootstrap

正如hughjdavey 在他的评论中所说,您还需要以下导入行:从引导程序"导入 * 作为引导程序;从'jquery'导入*作为$;

As hughjdavey said in his comment, you also need the following import lines: import * as bootstrap from "bootstrap"; import * as $ from 'jquery';

这篇关于错误 TS2339:“JQuery"类型上不存在属性“模态"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆