Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to write comments with AngularJS so that they are not visible when viewing the source

Tags:

When writing JSPs, I always use <%-- --%> instead of <!-- --> to write any comments, since it will not output to the HTML. I have begun using AngularJS, and I'm wondering if there's any similar kind of comment construct that I could use. It's not absolutely necessary to not have the comments visible in the HTML source, but I much rather them not being there.

With the limited knowledge I have of AngularJS, I'm not sure how they could prevent it from being in the source, but I just want to ask in case there is a way. Perhaps there's also a best practice for comments in AngularJS? Any input would be appreciated.

like image 507
dnc253 Avatar asked Jul 04 '12 19:07

dnc253


People also ask

Does angular remove HTML comments?

Unfortunately for my case, Angular removes all comments from the template during processing. Hence this first attempt resulted in an empty component. The setTimeout call is used in order for HTML rendering to complete before createComment is called.

How do you indicate a comment of this is a comment in a JavaScript?

Any text between a // and the end of a line is treated as a comment and is ignored by JavaScript. Any text between the characters /* and */ is treated as a comment.

What is not recommended in AngularJS?

It is tempting to do too much work in the AngularJS controller. After all, the controller is where the view first has access to JavaScript via $scope functions. However, doing this will cause you to miss out on code sharing across the site and is not recommended by AngularJS documentation.


1 Answers

AngularJS is a library for dynamic features in HTML/JS/CSS pages. It's not a template language such as JavaServer Pages. As such, it doesn't have a special syntax for comments. You can still use HTML style comments of course.

like image 191
Simeon Visser Avatar answered Oct 05 '22 15:10

Simeon Visser