diff --git a/src/ng/compile.js b/src/ng/compile.js index 8741dc4d074a..631ddc67cedd 100644 --- a/src/ng/compile.js +++ b/src/ng/compile.js @@ -3679,8 +3679,9 @@ function removeComments(jqNodes) { while (i--) { var node = jqNodes[i]; - if (node.nodeType === NODE_TYPE_COMMENT) { - splice.call(jqNodes, i, 1); + if (node.nodeType === NODE_TYPE_COMMENT || + (node.nodeType === NODE_TYPE_TEXT && node.nodeValue.trim() === '')) { + splice.call(jqNodes, i, 1); } } return jqNodes; diff --git a/test/ng/compileSpec.js b/test/ng/compileSpec.js index e4a8ddf4e960..70112d14a82f 100755 --- a/test/ng/compileSpec.js +++ b/test/ng/compileSpec.js @@ -1364,6 +1364,22 @@ describe('$compile', function() { }); }); + it('should ignore whitespace betwee comment and root node when replacing with a template', function() { + module(function() { + directive('replaceWithWhitespace', valueFn({ + replace: true, + template: '

Hello, world!

' + })); + }); + inject(function($compile, $rootScope) { + expect(function() { + element = $compile('
')($rootScope); + }).not.toThrow(); + expect(element.find('p').length).toBe(1); + expect(element.find('p').text()).toBe('Hello, world!'); + }); + }); + it('should keep prototype properties on directive', function() { module(function() { function DirectiveClass() { @@ -2092,6 +2108,18 @@ describe('$compile', function() { $compile('

'); $rootScope.$apply(); expect($exceptionHandler.errors).toEqual([]); + + // comments are ok + $templateCache.put('template.html', '
\n'); + $compile('

'); + $rootScope.$apply(); + expect($exceptionHandler.errors).toEqual([]); + + // white space around comments is ok + $templateCache.put('template.html', '
\n'); + $compile('

'); + $rootScope.$apply(); + expect($exceptionHandler.errors).toEqual([]); }); }); @@ -2303,6 +2331,26 @@ describe('$compile', function() { }); }); + it('should ignore whitespace between comment and root node when replacing with a templateUrl', function() { + module(function() { + directive('replaceWithWhitespace', valueFn({ + replace: true, + templateUrl: 'templateWithWhitespace.html' + })); + }); + inject(function($compile, $rootScope, $httpBackend) { + $httpBackend.whenGET('templateWithWhitespace.html'). + respond('

Hello, world!

'); + expect(function() { + element = $compile('
')($rootScope); + }).not.toThrow(); + $httpBackend.flush(); + expect(element.find('p').length).toBe(1); + expect(element.find('p').text()).toBe('Hello, world!'); + }); + }); + + it('should keep prototype properties on sync version of async directive', function() { module(function() { function DirectiveClass() {