3

I have a directive link function. By default angular link functions is a post link function, isn't it? How to make that as pre link?

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

BTW, it use require.

Praveen Prasannan
  • 7,093
  • 10
  • 50
  • 70

1 Answers1

0

You will need to implement the compile function and return the prelink function from it.

Taken from Angular's docs (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( ... ) { ... }
},
pablochan
  • 5,625
  • 27
  • 42