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

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.

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.


You should use a pre-deployment processing tool such as grunt uglify. It will allow you to strip out comments and do more useful deployment pre-processing such as minifying code.

grunt uglify


Use directives:

myApp.directive('comment', ['$rootScope', function($rootScope) {

    return {
        restrict: 'AEC',
        link: function($scope, element, attrs){
            $(element).remove();
        }
    };
}]);

example:

<comment>Remove me</comment>

Need Your Help

How does @synchronized lock/unlock in Objective-C?

objective-c synchronization

Does @synchronized not use "lock" and "unlock" to achieve mutual exclusion? How does it do lock/unlock then?

why are draw calls expensive?

performance optimization graphics 3d gpu

assuming the texture, vertex, and shader data are already on the graphics card, you don't need to send much data to the card. there's a few bytes to identify the data, and presumably a 4x4 matrix, ...