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

Commit cd21602

Browse files
committed
fix(ngBindHtml): throw error if interpolation is used in expression
Closes #8824
1 parent 5f3f25a commit cd21602

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/ng/directive/ngBind.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -186,14 +186,14 @@ var ngBindHtmlDirective = ['$sce', '$parse', '$compile', function($sce, $parse,
186186
return {
187187
restrict: 'A',
188188
compile: function ngBindHtmlCompile(tElement, tAttrs) {
189+
var ngBindHtmlGetter = $parse(tAttrs.ngBindHtml);
190+
var ngBindHtmlWatch = $parse(tAttrs.ngBindHtml, function getStringValue(value) {
191+
return (value || '').toString();
192+
});
189193
$compile.$$addBindingClass(tElement);
190194

191195
return function ngBindHtmlLink(scope, element, attr) {
192196
$compile.$$addBindingInfo(element, attr.ngBindHtml);
193-
var ngBindHtmlGetter = $parse(attr.ngBindHtml);
194-
var ngBindHtmlWatch = $parse(attr.ngBindHtml, function getStringValue(value) {
195-
return (value || '').toString();
196-
});
197197

198198
scope.$watch(ngBindHtmlWatch, function ngBindHtmlWatchAction() {
199199
// we re-evaluate the expr because we want a TrustedValueHolderType

test/ng/directive/ngBindSpec.js

+8
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,14 @@ describe('ngBind*', function() {
122122

123123
describe('ngBindHtml', function() {
124124

125+
it('should complain about accidental use of interpolation', inject(function($compile) {
126+
expect(function() {
127+
$compile('<div ng-bind-html="{{myHtml}}"></div>');
128+
}).toThrowMinErr('$parse', 'syntax', "Syntax Error: Token 'myHtml' is unexpected, " +
129+
"expecting [:] at column 3 of the expression [{{myHtml}}] starting at [myHtml}}].");
130+
}));
131+
132+
125133
describe('SCE disabled', function() {
126134
beforeEach(function() {
127135
module(function($sceProvider) { $sceProvider.enabled(false); });

0 commit comments

Comments
 (0)