0

我試圖寫一個指令限制CTypeScript但鏈接沒有被調用。我錯過了什麼?角度指令限制「C」不能正常工作

/// <reference path="../../../typings/jquery.tooltipster/jquery.tooltipster.d.ts" /> 
/// <reference path="../../../typings/angularjs/angular.d.ts" /> 
/// <reference path="../stationstaff.ts" /> 

module App.StationStaff { 

    class BedDetailDirective implements ng.IDirective { 

     public static factory() { 
      var directive =() => new BedDetailDirective(); 
      directive.$inject = []; 

      return directive; 
     } 

     public restrict = "C"; 

     public link($scope: ng.IScope, element: JQuery, attributes: ng.IAttributes) { 
      var $element = $(element); 
      var content = "<div class='tooltipster-header'><span>Art: Elektrisch</span></div><div class='tooltipster-body'><span>ID: BSHR1114</span><span>Ort: Station SR.1 - Raum: 10</span><span>Hersteller: Hill-Rom</span><span>Nächster Service: 31.05.2015</span></div>"; 

      $element.tooltipster({ 
       content: content, 
       contentAsHTML: true, 
       animation: "fade", 
       theme: "hpm-tooltipster", 
       position: "right", 
       trigger: "click", 
       functionReady(e) { 
        e.addClass("hpm-item-active"); 
       }, 
       functionAfter(e) { 
        e.removeClass("hpm-item-active"); 
       } 
      }); 
     } 
    } 

    angular.module("appStationStaff", []) 
     .directive("tooltip", BedDetailDirective.factory()); 
} 



<ion-view ng-controller="bedFinderResultController as vm"> 
    <ion-content> 
     <div class="list"> 
      <div class="item item-balanced item-icon-right item-royal hpm-item-medium" ng-repeat="bed in vm.beds"> 
       <div class="hpm-item-icon text-center ion-ios-information-outline tooltip"> 
       </div> 
       <div class="hpm-bed-availability-red"></div> <!-- TODO: Color should come from controller --> 
       <div class="row"> 
        <div class="col"> 
         <div class="row"> 
          <div class="hpm-item-title"> 
           <span>Type: {{bed.type}}</span> 
          </div> 
         </div> 
         <div class="row"> 
          <div class="hpm-item-subtitle"> 
           <span>{{bed.location}} - Room: {{bed.room}}</span> 
          </div> 
         </div> 
        </div> 
        <div class="col"> 
         <div class="row"> 
          <i class="icon ion-ios-arrow-right"></i> 
         </div> 
        </div> 
       </div> 
      </div> 
     </div> 
    </ion-content> 
</ion-view> 

回答

0

的問題是你的指令在工廠設置:

public static factory() { 
    var directive =() => new BedDetailDirective(); 
    directive.$inject = []; 
    return directive(); // NOTE: calling the function 
} 

註冊一個指令定義是返回一個對象的函數和對象是指令定義對象(DDO)。

上面返回的是返回返回DDO的函數的函數。只需進行更改即可返回該函數的執行而不是函數本身。