0

I have written a directive by using typescript. The code is look like this.

'use strict';

module App.Directives {

    interface IPageModal extends ng.IDirective {
    }

    interface IPageModalScope extends ng.IScope {
        //modal: any;
    }

    class PageModal implements IPageModal {
        static directiveId: string = 'pageModal';
        restrict: string = "A";

        constructor(private $parse: IPageModalScope) {
        }

        link = (scope: IPageModalScope, element, attrs) => {

            element.on('click', function (event) {
                event.preventDefault();

                var options = {
                    backdrop: 'static',
                    keyboard: false
                };
                event.openModal = function () {
                    $('#' + attrs['targetModal']).modal(options);//error
                };
                event.showModal = function () {
                    $('#' + attrs['targetModal']).modal('show');//error
                };
                event.closeModal = function () {
                    $('#' + attrs['targetModal']).modal('hide');//error
                };
                var fn = this.$parse(attrs['pageModal']);
                fn(scope, { $event: event });
            });
        }
    }

    //References angular app
    app.directive(PageModal.directiveId, ['$parse', ($parse) => new PageModal($parse)]);
}

When I call jquery bootstrap .modal function then error occurring. How can i call this function below

$('#' + attrs['targetModal']).modal('hide'); //error line of code

1 Answer 1

1

jquery bootstrap .modal function then error occurring

If its a compile time error you need a type definition. More : https://basarat.gitbooks.io/typescript/content/docs/types/ambient/d.ts.html

Fix

A quick one in foo.d.ts:

interface JQuery {
  modal: any;
}
Sign up to request clarification or add additional context in comments.

4 Comments

How can i call this line $('#' + attrs['targetModal']).modal('hide');
With jquery.d.ts and the foo.d.ts that I provided : your code $('#' + attrs['targetModal']).modal('hide'); will compile just fine
.modal is the function of twitter bootstrap

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.