错误TS2339:类型"JQuery"上不存在属性“模式" [英] error TS2339: Property 'modal' does not exist on type 'JQuery'
问题描述
我在AngularJS中使用Typescript. 我对使用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' />
推荐答案
具有较新版本的打字稿(我相信> v2):
with newer versions of typescript (>v2 i believe):
npm install -D @types/bootstrap
正如hughjdavey在评论中所说,您还需要以下导入行: 从"bootstrap"导入*作为引导程序; 从'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屋!