From d804bbcd51ec83bee1f4a3ccd42c3bd7eb38a988 Mon Sep 17 00:00:00 2001 From: Brian Ford Date: Thu, 19 Jul 2012 14:07:00 -0700 Subject: [PATCH] feat($interpolate): provide contextual error messages if an exception occurs during interpolation of a string (e.g. name() in "Hello, {{name()}}!" throws an exception) we now print an error message with the expression that was being evaluated when the exception was thrown. --- src/ng/interpolate.js | 26 ++++++++++++++++---------- test/BinderSpec.js | 2 +- test/ng/interpolateSpec.js | 23 +++++++++++++++++++++++ 3 files changed, 40 insertions(+), 11 deletions(-) diff --git a/src/ng/interpolate.js b/src/ng/interpolate.js index 149f0c868963..dcf05d778f3e 100644 --- a/src/ng/interpolate.js +++ b/src/ng/interpolate.js @@ -52,7 +52,7 @@ function $InterpolateProvider() { }; - this.$get = ['$parse', function($parse) { + this.$get = ['$parse', '$exceptionHandler', function($parse, $exceptionHandler) { var startSymbolLength = startSymbol.length, endSymbolLength = endSymbol.length; @@ -124,18 +124,24 @@ function $InterpolateProvider() { if (!mustHaveExpression || hasInterpolation) { concat.length = length; fn = function(context) { - for(var i = 0, ii = length, part; i{{1 + 1}}
{{err()}}
{{1 + 2}}
'); + $compile(dom)($rootScope); + expect(function () { + $rootScope.$apply(); + }).toThrow('Error while interpolating: {{err()}}\nError: oops'); + expect(dom[0].innerHTML).toEqual('2'); + expect(dom[1].innerHTML).toEqual('{{err()}}'); + expect(dom[2].innerHTML).toEqual('{{1 + 2}}'); + })); + it('should return interpolation function', inject(function($interpolate, $rootScope) { $rootScope.name = 'Misko';