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

feat($interpolate): Add 'strictMode' option on $interpolateProvider to tell $compileProvider not to denormalize directives template. #6453

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ng/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {

var startSymbol = $interpolate.startSymbol(),
endSymbol = $interpolate.endSymbol(),
denormalizeTemplate = (startSymbol == '{{' || endSymbol == '}}')
denormalizeTemplate = ($interpolate.strictMode() || startSymbol == '{{' || endSymbol == '}}')
? identity
: function denormalizeTemplate(template) {
return template.replace(/\{\{/g, startSymbol).replace(/}}/g, endSymbol);
Expand Down
35 changes: 35 additions & 0 deletions src/ng/interpolate.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ var $interpolateMinErr = minErr('$interpolate');
function $InterpolateProvider() {
var startSymbol = '{{';
var endSymbol = '}}';
var strictMode = false;

/**
* @ngdoc method
Expand All @@ -60,6 +61,25 @@ function $InterpolateProvider() {
}
};

/**
* @ngdoc method
* @name $interpolateProvider#strictMode
* @description
* If strictMode is on, $CompileProvider will NOT denormalize Directives templates:
* default symbols '{{' and '}}' will NOT be supported anymore.
*
* @param {boolean=} true to disable denormalizeTemplate() in $CompileProvider
* @returns {boolean|self} true if strict mode is enabled, false otherwise.
*/
this.strictMode = function(value){
if (value !== undefined) {
strictMode = value;
return this;
} else {
return strictMode;
}
};

/**
* @ngdoc method
* @name $interpolateProvider#endSymbol
Expand Down Expand Up @@ -232,6 +252,21 @@ function $InterpolateProvider() {
return endSymbol;
};


/**
* @ngdoc method
* @name $interpolate#strictMode
* @description
* If strictMode is on, $CompileProvider will NOT denormalize Directives templates:
* default symbols '{{' and '}}' will NOT be supported anymore.
*
* @returns {boolean} true if strict mode is enabled, false otherwise.
*/
$interpolate.strictMode = function() {
return strictMode;
};


return $interpolate;
}];
}
Expand Down