angularjscomments

How can I add a comment (for developers, not in output HTML) to an Angular template?


I'm used to the more popular 'mustache' style templates where I can add a comment for my colleagues with:

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

These comments obviously don't appear in the output - so users don't see them. How can I do something similar in Angular?


Solution

  • I realize it has been over 7 years since this question has been asked, but it is one of the top search results for "angular template comment" so here we go...

    Since there still does not seem to be template syntax support for (non-html) comments the easiest way I found to do this is abusing the support for one line js comments in embedded expressions. Like this:

    {{ '' // my comment }}
    

    The empty string literal - which makes this even more ugly than it already is - is necessary because without it the angular compiler barfs out a 'ERROR in TypeError: Cannot read property 'visit' of undefined', at least with the 9.0.0 version I am on.

    Yay web development in 2021!