From 486e88809eee190e51717891bd0585a404e73209 Mon Sep 17 00:00:00 2001 From: cexbrayat Date: Fri, 30 May 2014 16:03:21 +0200 Subject: [PATCH] fix($parse): fix parsing error with leading space and one time bind Closes 7640 --- src/ng/parse.js | 2 ++ test/ng/compileSpec.js | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/ng/parse.js b/src/ng/parse.js index bb59ea136e59..6fb3a92b6229 100644 --- a/src/ng/parse.js +++ b/src/ng/parse.js @@ -1024,6 +1024,8 @@ function $ParseProvider() { switch (typeof exp) { case 'string': + exp = trim(exp); + if (exp.charAt(0) === ':' && exp.charAt(1) === ':') { oneTime = true; exp = exp.substring(2); diff --git a/test/ng/compileSpec.js b/test/ng/compileSpec.js index 1095a76b6805..1e9ca19fdc25 100755 --- a/test/ng/compileSpec.js +++ b/test/ng/compileSpec.js @@ -2196,6 +2196,22 @@ describe('$compile', function() { }) ); + it('should one-time bind if the expression starts with a space and two colons', inject( + function($rootScope, $compile) { + $rootScope.name = 'angular'; + element = $compile('
text: {{ ::name }}
')($rootScope); + expect($rootScope.$$watchers.length).toBe(2); + $rootScope.$digest(); + expect(element.text()).toEqual('text: angular'); + expect(element.attr('name')).toEqual('attr: angular'); + expect($rootScope.$$watchers.length).toBe(0); + $rootScope.name = 'not-angular'; + $rootScope.$digest(); + expect(element.text()).toEqual('text: angular'); + expect(element.attr('name')).toEqual('attr: angular'); + }) + ); + it('should process attribute interpolation in pre-linking phase at priority 100', function() { module(function() {