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

Commit 924ee6d

Browse files
committed
fix($interpolate): don't ReferenceError when context is undefined
546cb42 introduced a regression, which would cause the function returned from $interpolate to throw a ReferenceError if `context` is undefined. This change prevents the error from being thrown. Closes #7230 Closes #7237
1 parent cbc7496 commit 924ee6d

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/ng/interpolate.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ function $InterpolateProvider() {
199199
};
200200

201201
return extend(function interpolationFn(context) {
202-
var scopeId = context.$id || 'notAScope';
202+
var scopeId = (context && context.$id) || 'notAScope';
203203
var lastValues = lastValuesCache.values[scopeId];
204204
var lastResult = lastValuesCache.results[scopeId];
205205
var i = 0;
@@ -214,7 +214,7 @@ function $InterpolateProvider() {
214214
if (!lastValues) {
215215
lastValues = [];
216216
inputsChanged = true;
217-
if (context.$on) {
217+
if (context && context.$on) {
218218
context.$on('$destroy', function() {
219219
lastValuesCache.values[scopeId] = null;
220220
lastValuesCache.results[scopeId] = null;

test/ng/interpolateSpec.js

+5
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ describe('$interpolate', function() {
5151
}));
5252

5353

54+
it('should interpolate with undefined context', inject(function($interpolate) {
55+
expect($interpolate("Hello, world!{{bloop}}")()).toBe("Hello, world!");
56+
}));
57+
58+
5459
describe('interpolating in a trusted context', function() {
5560
var sce;
5661
beforeEach(function() {

0 commit comments

Comments
 (0)