Angular 2+: how to remove all angular attributes and comments (and other angular artifacts) from the HTML code?

后端 未结 2 1625
[愿得一人]
[愿得一人] 2021-01-07 03:11

I want to utilise Angular in a not really usual way. I use it to generate the HTML that is later on used for various needs.

Why? I want this HTML to be static and in

2条回答
  •  星月不相逢
    2021-01-07 04:00

    You'll have to post-process the HTML using a library such as Tidy.

    Tidy has options to strip attributes that aren't on a white-list and also remove comments, but it's a library and has to be run on a string or text file.

    Tidy can be run via different platforms like PHP, NodeJS or .NET. Here's a NodeJS library:

    https://github.com/vavere/htmltidy

    Another option would be to use jQuery to update the DOM using a broad $('*').each() and just mutate the DOM elements before saving the HTML to where you need it.

提交回复
热议问题