angularjs - 如何向 Angular 模板添加注释(针对开发人员,而不是在输出 HTML 中)?

标签 angularjs comments

我习惯了更流行的“ mustache ”样式模板,我可以在其中为同事添加评论:

{# The following code looks a bit odd, but here's why... #}

这些注释显然不会出现在输出中 - 因此用户看不到它们。我怎样才能在 Angular 中做类似的事情?

最佳答案

Angular 没有内置模板注释支持。但是,您可以创建一个注释指令来支持它,如下所示。

app.directive('templateComment', function () {
    return {
        restrict: 'E',
        compile: function (tElement, attrs) {
            tElement.remove();
        }
    };
});

标记将是:

<template-comment>Put your comment here.</template-comment>

或者,您可以使用标准 html 注释,然后在部署之前将它们从生产代码中删除。

如果您想支持 block 注释,请考虑这个繁重的任务 - https://github.com/philipwalton/grunt-strip-code指定开始注释和结束注释,假设您将此任务添加到部署目标中,您的注释 block 将从生产代码中删除。如果您不使用 Grunt,请将其用作构建过程的模型。 ....

关于angularjs - 如何向 Angular 模板添加注释(针对开发人员,而不是在输出 HTML 中)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18063475/

相关文章:

python - 带有 Angular 的 flask : POST form is empty

html - JSP 页面中缺少 HTML 注释

django - 表单对象没有属性 'has_header'

eclipse - 如何在 Eclipse 中注释 block ?

angularjs - 如何调用 View 内部 Controller 中定义的函数?

c# - 如何从 Webapi 将 URL 传递到 <img> 标记以接受 base64 图像?

javascript - 如何在 Protractor 的 <td> </td> 中显示文本

javascript - 递归地在ng-repeat中迭代时如何在ng-include中获取父元素

java - 反编译能看到Java注释吗?

php - 获取每个帖子的评论