我有一个问题是什么是指令的等价物:编译(前/后)?
javascript中的示例:
angular.module('app').directive('checkBox', function () {
return {
//... my directive options
compile: function () {
return function () {
pre: function (scope) {}
post: function (scope) {}
}
}
}
});
TypeScript与此等效的是什么?
答案 0 :(得分:8)
这相当于:
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) => {
}
};
}
答案 1 :(得分:6)
如果您使用http://definitelytyped.org/tsd/
中的引用就像
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) => {
}
};
};
答案 2 :(得分:1)
您的compile
返回值不正确。你应该返回一个不是函数的对象:
compile: function () {
return { // no `function ()`
pre: function (scope) {}
post: function (scope) {}
}
}
此代码段将与TypeScript一样工作。