Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Commit

Permalink
few fixes about flags to compile css class and comment directives con…
Browse files Browse the repository at this point in the history
…ditionally
  • Loading branch information
drpicox committed Jul 29, 2016
1 parent 4bde767 commit af05406
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 33 deletions.
20 changes: 15 additions & 5 deletions docs/content/guide/production.ngdoc
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,23 @@ For more information, see the

## Disable comment and css class directives

By default AngularJS compiles and executes all directives inside comments and element classes. In order to perform this task, angular compiler must look for directives by:
By default AngularJS compiles and executes all directives inside comments and element classes.
In order to perform this task, angular compiler must look for directives by:

- Parse all your application element classes.

- Parse all your application html comments.

Nowadays most of the Angular projects are using only element and attribute directives, and in such projects there is no need to compile comments and classes.
Nowadays most of the Angular projects are using only element and attribute directives,
and in such projects there is no need to compile comments and classes.

If you are sure that your project only use element directives and attribute directives, and you are not using any 3rd part library that uses directives inside element classes or html comments, you can disable.
This results in a compilation performance gain, as the compiler does not have to check comments and element classes looking for directives.
If you are sure that your project only uses element and attribute directives,
and you are not using any 3rd part library that uses
directives inside element classes or html comments,
you can disable the compilation of directives on element classes and comments
for the whole application.
This results in a compilation performance gain,
as the compiler does not have to check comments and element classes looking for directives.

To disable comment and css class directives use the `$compileProvider`:

Expand All @@ -95,5 +102,8 @@ $compileProvider.commentDirectivesEnabled(false);
$compileProvider.cssClassDirectivesEnabled(false);
```

For more see the docs pages on {@link ng.$compileProvider#commentDirectivesEnabled `$compileProvider.commentDirectivesEnabled`} and {@link ng.$compileProvider#cssClassDirectivesEnabled `$compileProvider.cssClassDirectivesEnabled`}.
For more see the docs pages on
{@link ng.$compileProvider#commentDirectivesEnabled `$compileProvider.commentDirectivesEnabled`}
and
{@link ng.$compileProvider#cssClassDirectivesEnabled `$compileProvider.cssClassDirectivesEnabled`}.

44 changes: 16 additions & 28 deletions src/ng/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -1386,7 +1386,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
return TTL;
};

var COMMENT_DIRECTIVES_ENABLED = true;
var commentDirectivesEnabledConfig = true;
/**
* @ngdoc method
* @name $compileProvider#commentDirectivesEnabled
Expand All @@ -1400,28 +1400,22 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
* on comments for the whole application.
* This results in a compilation performance gain,
* as the compiler doesn't have to check comments when looking for directives.
* This should however only be used if you are sure that no comment directives are used in the application
* (including any 3rd party directives).
* This should however only be used if you are sure that no comment directives are used in
* the application (including any 3rd party directives).
*
* Example:
*
* ```
* $compileProvider.commentDirectivesEnabled(false);
* ```
*
* @param {boolean} false if the compiler may ignore directives on comments
* @returns {number|object} the current value (or `this` if called as a setter for chaining)
* @param {boolean} enabled `false` if the compiler may ignore directives on comments
* @returns {boolean|object} the current value (or `this` if called as a setter for chaining)
*/
this.commentDirectivesEnabled = function(value) {
if (arguments.length) {
COMMENT_DIRECTIVES_ENABLED = value;
commentDirectivesEnabledConfig = value;
return this;
}
return COMMENT_DIRECTIVES_ENABLED;
return commentDirectivesEnabledConfig;
};


var CSS_CLASS_DIRECTIVES_ENABLED = true;
var cssClassDirectivesEnabledConfig = true;
/**
* @ngdoc method
* @name $compileProvider#cssClassDirectivesEnabled
Expand All @@ -1435,24 +1429,18 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
* on element classes for the whole application.
* This results in a compilation performance gain,
* as the compiler doesn't have to check element classes when looking for directives.
* This should however only be used if you are sure that no class directives are used in the application
* (including any 3rd party directives).
*
* Example:
*
* ```
* $compileProvider.cssClassDirectivesEnabled(false);
* ```
* This should however only be used if you are sure that no class directives are used in
* the application (including any 3rd party directives).
*
* @param {boolean} false if the compiler may ignore directives on element classes
* @returns {number|object} the current value (or `this` if called as a setter for chaining)
* @param {boolean} enabled `false` if the compiler may ignore directives on element classes
* @returns {boolean|object} the current value (or `this` if called as a setter for chaining)
*/
this.cssClassDirectivesEnabled = function(value) {
if (arguments.length) {
CSS_CLASS_DIRECTIVES_ENABLED = value;
cssClassDirectivesEnabledConfig = value;
return this;
}
return CSS_CLASS_DIRECTIVES_ENABLED;
return cssClassDirectivesEnabledConfig;
};

this.$get = [
Expand All @@ -1465,8 +1453,8 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
var specialAttrHolder = window.document.createElement('div');


var commentDirectivesEnabled = COMMENT_DIRECTIVES_ENABLED;
var cssClassDirectivesEnabled = CSS_CLASS_DIRECTIVES_ENABLED;
var commentDirectivesEnabled = commentDirectivesEnabledConfig;
var cssClassDirectivesEnabled = cssClassDirectivesEnabledConfig;


var onChangesTtl = TTL;
Expand Down

0 comments on commit af05406

Please sign in to comment.