diff --git a/src/ng/directive/ngBind.js b/src/ng/directive/ngBind.js index e1891a1a960a..5dbb0a66e87a 100644 --- a/src/ng/directive/ngBind.js +++ b/src/ng/directive/ngBind.js @@ -186,14 +186,14 @@ var ngBindHtmlDirective = ['$sce', '$parse', '$compile', function($sce, $parse, return { restrict: 'A', compile: function ngBindHtmlCompile(tElement, tAttrs) { + var ngBindHtmlGetter = $parse(tAttrs.ngBindHtml); + var ngBindHtmlWatch = $parse(tAttrs.ngBindHtml, function getStringValue(value) { + return (value || '').toString(); + }); $compile.$$addBindingClass(tElement); return function ngBindHtmlLink(scope, element, attr) { $compile.$$addBindingInfo(element, attr.ngBindHtml); - var ngBindHtmlGetter = $parse(attr.ngBindHtml); - var ngBindHtmlWatch = $parse(attr.ngBindHtml, function getStringValue(value) { - return (value || '').toString(); - }); scope.$watch(ngBindHtmlWatch, function ngBindHtmlWatchAction() { // we re-evaluate the expr because we want a TrustedValueHolderType diff --git a/test/ng/directive/ngBindSpec.js b/test/ng/directive/ngBindSpec.js index 2a1f00637044..5f65bfa907e1 100644 --- a/test/ng/directive/ngBindSpec.js +++ b/test/ng/directive/ngBindSpec.js @@ -122,6 +122,14 @@ describe('ngBind*', function() { describe('ngBindHtml', function() { + it('should complain about accidental use of interpolation', inject(function($compile) { + expect(function() { + $compile('
'); + }).toThrowMinErr('$parse', 'syntax', "Syntax Error: Token 'myHtml' is unexpected, " + + "expecting [:] at column 3 of the expression [{{myHtml}}] starting at [myHtml}}]."); + })); + + describe('SCE disabled', function() { beforeEach(function() { module(function($sceProvider) { $sceProvider.enabled(false); });