diff --git a/src/ng/interpolate.js b/src/ng/interpolate.js index 9ac68e8b7727..adcb1d3e42fe 100644 --- a/src/ng/interpolate.js +++ b/src/ng/interpolate.js @@ -199,7 +199,7 @@ function $InterpolateProvider() { }; return extend(function interpolationFn(context) { - var scopeId = context.$id || 'notAScope'; + var scopeId = (context && context.$id) || 'notAScope'; var lastValues = lastValuesCache.values[scopeId]; var lastResult = lastValuesCache.results[scopeId]; var i = 0; @@ -214,7 +214,7 @@ function $InterpolateProvider() { if (!lastValues) { lastValues = []; inputsChanged = true; - if (context.$on) { + if (context && context.$on) { context.$on('$destroy', function() { lastValuesCache.values[scopeId] = null; lastValuesCache.results[scopeId] = null; diff --git a/test/ng/interpolateSpec.js b/test/ng/interpolateSpec.js index 864b4b87d06c..099a8606994e 100644 --- a/test/ng/interpolateSpec.js +++ b/test/ng/interpolateSpec.js @@ -51,6 +51,11 @@ describe('$interpolate', function() { })); + it('should interpolate with undefined context', inject(function($interpolate) { + expect($interpolate("Hello, world!{{bloop}}")()).toBe("Hello, world!"); + })); + + describe('interpolating in a trusted context', function() { var sce; beforeEach(function() {