Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
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'.'
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
I'm referencing to jquery.d.ts
in 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' />
–
–
–
Edit:
As hughjdavey said in his comment, you also need the following import lines:
import * as bootstrap from "bootstrap";
import * as $ from 'jquery';
–
–
–
–
–
Your problem is caused by the lack of property with name modal
in the jquery.d.ts file.
If you sure that this work in pure JS you can trick with it like this
$scope.delete = function (id) {
Photo.get({id: id}, function(result) {
$scope.photo = result;
(<any>$('#deletePhotoConfirmation')).modal('show');
Also, you can find additional d.ts
file where this option has already been defined.
Try to consider this library that has already had modal
option
Good Luck!
When I upgrade angular to version 9, I faced this issue.
Here are my solution, I shared for whom concerned.
Property 'modal' does not exist on type 'JQuery'
$('#ManualMinMaxModal').modal('show');
change to
($('#ManualMinMaxModal') as any).modal('show');
Property 'DataTable' does not exist on type 'JQuery'
$('#realTimeTable').DataTable()
change to
($('#realTimeTable') as any).DataTable()
!$.fn.DataTable.isDataTable('#realTimeTable')
change to
!($.fn as any).DataTable.isDataTable('#realTimeTable')
Updated:
cast to any sometime not work, and finally solution is change declare from import * as $ from 'jquery'
to declare var $: any;
Solution for Angular 8+ versions :
Not working:
$('#deletePhotoConfirmation').modal('show');
Instead use this:
($('#deletePhotoConfirmation') as any).modal('show');
For Import :
import * as $ from 'jquery';
Good Luck
Yep, I too had to include both of these imports in order to make my app publishable by angular:
import * as bootstrap from "bootstrap";
import * as $ from "jquery";
I added them in the component that was using jQuery.
Did you add bootstrap.js
to your angular.json?
"scripts": [
"node_modules/jquery/dist/jquery.min.js",
"node_modules/bootstrap/dist/js/bootstrap.min.js"
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.