是否可以从自我指令编译函数访问指令名称?
只是为了更好地解释我的意思:angularjs:是否有可能从自指令编译函数访问指令名称?
app.directive('myDirective', function() {
return {
scope: {},
compile: function(element, attrs) {
if (!attr.mandatoryParameter) return err(element, 'mandatory parameter not specified!');
element.replaceWith('... ok ...');
}
};
function err(el, reason) {
el.replaceWith(I_WOULD_LIKE_TO_PRINT_MY_DIRECTIVE_HERE__ + ': ' + reason);
}
});
为什么你只是硬编码? – Nix
我不喜欢重复代码... :-) – MarcoS