3

我有一個指令鏈接功能。默認的角度鏈接函數是一個後鏈接函數,不是嗎?如何將其作爲預先鏈接?將角度指示鏈接功能作爲預鏈接嗎?

app.directive("textBoxCol", function() { 
     return { 
      require: "^grid", 
      restrict: "E", 
      replace: true, 
      scope: { 
       title: "@title", 
       cssClass: "@class", 
       dataField: "@field" 
      }, 
      link: function ($scope, element, attrs, grid) { 
       $scope.type = ColumnType.TextBox; 
       tableControl.addColumn($scope); 
      } 
     }; 
    }); 

順便說一句,它使用的要求。

回答

0

您將需要實現compile函數並從中返回prelink函數。

compile: function compile(tElement, tAttrs, transclude) { 
    return { 
    pre: function preLink(scope, iElement, iAttrs, controller) { ... }, 
    post: function postLink(scope, iElement, iAttrs, controller) { ... } 
    } 
    // or 
    // return function postLink(...) { ... } 
}, 

從角的文檔(https://docs.angularjs.org/api/ng/service/%24compile)摘自