Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the equivalent for directive, compile (pre/post) in TypeScript?

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?

like image 930
hackp0int Avatar asked Oct 05 '14 12:10

hackp0int


People also ask

What is compile directive?

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.

What is Prelink and Postlink in AngularJS?

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.

What is $compile in Angular?

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.

What is the priority level of directives?

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.


2 Answers

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) => {

                }
            };
        }
like image 122
Vladimir Melekh Avatar answered Sep 28 '22 14:09

Vladimir Melekh


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) => {

                }
            };
        };
like image 28
maxisam Avatar answered Sep 28 '22 15:09

maxisam