2016-04-27 8 views
0

私はtypescriptを使って指令を書いた。コードはこのようになります。jsceryライブラリ関数をtypescriptに書き込む

'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)]); 
} 

jqueryブートストラップ.modal関数を呼び出すと、エラーが発生します。この関数を以下のように呼び出すにはどうすればいいですか?

$( '#' + attrs ['targetModal'])。あなたは型定義を必要とするコンパイル時エラーの場合は.modal機能ブートストラップコードの//エラー行

答えて

1

jqueryのは、

発生したエラー。多く:https://basarat.gitbooks.io/typescript/content/docs/types/ambient/d.ts.html

修正

foo.d.tsで迅速な1:

interface JQuery { 
    modal: any; 
} 
+0

あなたは私のコードを書き換えることはできますか? – Shohel

+0

私のアドオンであなたのコードはそのまま動作します – basarat

+0

どうすればこの行を$( '#' + attrs ['targetModal'])と呼ぶことができますか。 – Shohel

関連する問題