What is equivalent to directive to compile (pre / post) in TypeScript?

I have a question, which is equivalent to the 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 equivalent to TypeScript for this?

+5
source share
3 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) => { } }; } 
+8
source

if you use the link from http://definitelytyped.org/tsd/

it looks 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) => { } }; }; 
+6
source

You have the wrong return value from compile . You must return the object not as a function:

 compile: function () { return { // no `function ()` pre: function (scope) {} post: function (scope) {} } } 

This piece of code will work as with TypeScript.

+1
source

Source: https://habr.com/ru/post/1204045/


All Articles