I have a question what is the equivalent for directive: compile (pre/post)?
Example in javascript:
angular.module('app').directive('checkBox', function () {
  return {
      //... my directive options
      compile: function () {
           return function () {
               pre: function (scope) {}
               post: function (scope) {}
           }
      }
  }
});
What is TypeScript equivalent for this?
A compiler directive is an instruction to the compiler to complete a task before formally starting to compile the program, thus they are sometimes called pre-processor directives. Among other items, during the pre-processor step the compiler is looking for compiler directives and processes them as they are encountered.
Pre-linking function Executed before the child elements are linked. Not safe to do DOM transformation since the compiler linking function will fail to locate the correct elements for linking. Post-linking function Executed after the child elements are linked.
The $compile service is the service to use for compilation. Invoking $compile against markup will produce a function you can use to bind the markup against a particular scope (what Angular calls a linking function). After linking, you'll have DOM elements you can place into the browser.
Directives with greater numerical priority are compiled first. Pre-link functions are also run in priority order, but post-link functions are run in reverse order. The order of directives with the same priority is undefined. The default priority is 0.
It will be equivalent to:
public compile = (element: JQuery, attrs: angular.IAttributes, transclude: any): DirectivePrePost => {
            return {
                pre: ($scope: any, element: JQuery, attrs: angular.IAttributes) => {
                },
                post: ($scope: any, element: JQuery, attrs: angular.IAttributes) => {
                }
            };
        }
                        if you use the reference from http://definitelytyped.org/tsd/
it is like
compile = (tElem: ng.IAugmentedJQuery, tAttrs: ng.IAttributes, transclude: ng.ITranscludeFunction): ng.IDirectivePrePost => {
            return {
                pre: (scope: IOrderDetailDirScope, iElem: ng.IAugmentedJQuery, iAttrs: ng.IAttributes) => {
                },
                post: (scope: IOrderDetailDirScope, iElem: ng.IAugmentedJQuery, iAttrs: ng.IAttributes) => {
                }
            };
        };
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With