2016-04-29 2 views
1

動作しません。ここに私の指示があります。

'use strict'; 

    module App.Directives { 

    interface IPageModal extends ng.IDirective { 
    } 

    interface IPageModalScope extends ng.IScope { 

    } 

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

     constructor(private $parse: ng.IParseService) { 

     } 

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

      element.click((event) => { 
       event.preventDefault(); 

       var options = { 
        backdrop: 'static', 
        keyboard: false 
       }; 

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

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

<button class="btn blue-grey-900" target-modal="emplpyeeViewModal" page-modal="vm.addEmployee($event)"> 
    <i class="icon-plus m-b-xs"></i> 
</button> 

この行は動作しませんコントローラー

addEmployee($event) { 
    $event.openModal(); 
}; 

で使用中の

使用。 var fn = this.$parse(attrs['pageModal']);。私は何が間違っているのか理解できません。エラー

あるこの。$の解析は未定義です。 とサービスのそれはかなり些細だ2回

+0

この構文 '[ '$の解析'、($の解析)=>新しいPageModal($の解析)]は'本当に厄介になります。 ''($パース)=>新しいPageModal($の解析):アンギュラはすでにあなたが注入されたサービスのプロパティを持つクラスを作成し、さらにそれを2回以上行い、ファンキーな配列の注入を作るためにあなたを強制します。 10種類のサービスを注入するとどうなりますか?同じ名前を40回列挙していますか? – smnbbrv

答えて

0

と呼ばれる:function openmodal(event) {は、独自に定義しているので、あなたのthisは、あなたのclass'esスコープではありません。

例えば、クラスレベルで機能を宣言またはその代わりに矢印関数を使用

link = (scope: IPageModalScope, element, attrs) => { 
    element.click((event) => { 
     event.preventDefault(); 

     var options = { 
      backdrop: 'static', 
      keyboard: false 
     }; 

     event.openModal = function() { 
      $('#' + attrs['targetModal']).modal(options); 
     }; 
     event.showModal = function() { 
      $('#' + attrs['targetModal']).modal('show'); 
     }; 
     event.closeModal = function() { 
      $('#' + attrs['targetModal']).modal('hide'); 
     }; 
     var fn = this.$parse(attrs['pageModal']);//does not work here 
     fn(scope, { $event: event }); 
    }); 
} 
+0

同じエラーがこれ。$の解析は未定義です。 – Shohel

+0

こんにちは、ここに新しい問題、リンク関数は2回呼び出されます – Shohel

関連する問題