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

Commit

Permalink
fix($interpolate): don't ReferenceError when context is undefined
Browse files Browse the repository at this point in the history
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
  • Loading branch information
caitp committed May 2, 2014
1 parent cbc7496 commit 924ee6d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/ng/interpolate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions test/ng/interpolateSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 924ee6d

Please sign in to comment.