我有一个指令链接函数。默认情况下, Angular 链接函数是一个后链接函数,不是吗?如何将其设为预链接?
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);
}
};
});
顺便说一句,它使用 require。
最佳答案
您将需要实现compile
函数并从中返回prelink
函数。
摘自 Angular 的文档(https://docs.angularjs.org/api/ng/service/%24compile):
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( ... ) { ... }
},
关于javascript - 使 Angular Directive(指令)链接功能作为预链接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33893534/