diff --git a/src/Angular.js b/src/Angular.js index 20f8ce123343..73828eb8ab5a 100644 --- a/src/Angular.js +++ b/src/Angular.js @@ -1514,6 +1514,23 @@ function assertNotHasOwnProperty(name, context) { } } + +/** + * Throw an error when an interpolation is detected in an attribute value that should be an + * expression. + * + * @param attrs $attrs object + * @param attrName attribute name + */ +function assertNoInterpolation(attrs, attrName) { + if (/\{\{/.test(attrs[attrName])) { + throw new Error('Unexpected interpolation found in attribute ' + attrName + + ' of element ' + startingTag(attrs.$$element)); + } +}; + + + /** * Return the value accessible from the object by path. Any undefined traversals are ignored * @param {Object} obj starting object diff --git a/src/ng/directive/ngBind.js b/src/ng/directive/ngBind.js index 593bd292f990..aaf4cc98e212 100644 --- a/src/ng/directive/ngBind.js +++ b/src/ng/directive/ngBind.js @@ -179,6 +179,7 @@ var ngBindTemplateDirective = ['$interpolate', function($interpolate) { var ngBindHtmlDirective = ['$sce', '$parse', function($sce, $parse) { return { compile: function (tElement, tAttrs) { + assertNoInterpolation(tAttrs, 'ngBindHtml'); tElement.addClass('ng-binding'); return function (scope, element, attr) { diff --git a/test/ng/directive/ngBindSpec.js b/test/ng/directive/ngBindSpec.js index 166fdb705a4b..144670c8379a 100644 --- a/test/ng/directive/ngBindSpec.js +++ b/test/ng/directive/ngBindSpec.js @@ -129,6 +129,13 @@ describe('ngBind*', function() { })); + it('should complain about accidental use of interpolation', inject(function($compile) { + expect(function() { + $compile('
'); + }).toThrow('Unexpected interpolation found in attribute ngBindHtml of element
'); + })); + + describe('SCE disabled', function() { beforeEach(function() { module(function($sceProvider) { $sceProvider.enabled(false); });