1

I'm reviewing some code and I've run across an instance where the developer has added a placeholder for an Angular component.

<div>
  <!someAngularComponent/>
</div>

This behaves exactly as if <someAngularComponent/> were wrapped in the standard <!-- --> structure for comments.

Putting a single ! at the beginning of the tag seems to have some special meaning - see https://stackoverflow.com/a/16324326/217490. Is this usage a valid way to comment out elements, or is it working mostly by side effect?

Chad
  • 473
  • 7
  • 18
  • If you mean that the tag is just ignored by the browser, well, that's what happens with unknown or invalid markup. If you're talking about some processing made by your JavaScript framework then it probably isn't a simple HTML question. – Álvaro González Feb 15 '18 at 17:36

1 Answers1

2

Some browsers may support it as a comment, but it's not valid HTML. You can run the code through the W3C's validator to see: https://validator.w3.org/nu/#textarea

<!doctype html>
<html>
<head>
<title>Test</title>
</head>
<body>
<div>
<!someAngularComponent/>
</div>
</body>
</html>

This will raise an error:

Error: Bogus comment.

At line 8, column 3

body ↩ div ↩ !someAngularComp

Depending on your audience, you may have to test it in multiple browsers, but I'd probably just recommend the standard comment syntax so there's no risk.

Community
  • 1
  • 1
skyline3000
  • 7,639
  • 2
  • 24
  • 33