gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 22:16:11 35 4
gpt4 key购买 nike

我习惯了更流行的“ 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/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com