diff --git a/src/ng/compile.js b/src/ng/compile.js index 5b625c193478..c7cd08bce127 100644 --- a/src/ng/compile.js +++ b/src/ng/compile.js @@ -503,7 +503,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) { Suffix = 'Directive', COMMENT_DIRECTIVE_REGEXP = /^\s*directive\:\s*([\d\w\-_]+)\s+(.*)$/, CLASS_DIRECTIVE_REGEXP = /(([\d\w\-_]+)(?:\:([^;]+))?;?)/, - TABLE_CONTENT_REGEXP = /^<\s*(tr|th|td|tbody)(\s+[^>]*)?>/i; + TABLE_CONTENT_REGEXP = /^<\s*(tr|th|td|thead|tbody|tfoot)(\s+[^>]*)?>/i; // Ref: http://developers.whatwg.org/webappapis.html#event-handler-idl-attributes // The assumption is that future DOM event attribute names will begin with @@ -1649,16 +1649,15 @@ function $CompileProvider($provide, $$sanitizeUriProvider) { template = trim(template); if ((type = TABLE_CONTENT_REGEXP.exec(template))) { type = type[1].toLowerCase(); - var table = jqLite('' + template + '
'), - tbody = table.children('tbody'), - leaf = /(td|th)/.test(type) && table.find('tr'); - if (tbody.length && type !== 'tbody') { - table = tbody; + var table = jqLite('' + template + '
'); + if (/(thead|tbody|tfoot)/.test(type)) { + return table.children(type); } - if (leaf && leaf.length) { - table = leaf; + table = table.children('tbody'); + if (type === 'tr') { + return table.children('tr'); } - return table.contents(); + return table.children('tr').contents(); } return jqLite('
' + template + diff --git a/test/ng/compileSpec.js b/test/ng/compileSpec.js index 98b1650f7706..5110c4d62634 100755 --- a/test/ng/compileSpec.js +++ b/test/ng/compileSpec.js @@ -529,10 +529,18 @@ describe('$compile', function() { replace: true, template: 'TH' })); + directive('replaceWithThead', valueFn({ + replace: true, + template: 'TD' + })); directive('replaceWithTbody', valueFn({ replace: true, template: 'TD' })); + directive('replaceWithTfoot', valueFn({ + replace: true, + template: 'TD' + })); })); @@ -718,12 +726,26 @@ describe('$compile', function() { expect(nodeName_(element)).toMatch(/th/i); })); + it('should support templates with root tags', inject(function($compile, $rootScope) { + expect(function() { + element = $compile('
')($rootScope); + }).not.toThrow(); + expect(nodeName_(element)).toMatch(/thead/i); + })); + it('should support templates with root tags', inject(function($compile, $rootScope) { expect(function() { element = $compile('
')($rootScope); }).not.toThrow(); expect(nodeName_(element)).toMatch(/tbody/i); })); + + it('should support templates with root tags', inject(function($compile, $rootScope) { + expect(function() { + element = $compile('
')($rootScope); + }).not.toThrow(); + expect(nodeName_(element)).toMatch(/tfoot/i); + })); }); @@ -833,10 +855,18 @@ describe('$compile', function() { replace: true, templateUrl: 'th.html' })); + directive('replaceWithThead', valueFn({ + replace: true, + templateUrl: 'thead.html' + })); directive('replaceWithTbody', valueFn({ replace: true, templateUrl: 'tbody.html' })); + directive('replaceWithTfoot', valueFn({ + replace: true, + templateUrl: 'tfoot.html' + })); } )); @@ -1500,6 +1530,15 @@ describe('$compile', function() { expect(nodeName_(element)).toMatch(/th/i); })); + it('should support templates with root tags', inject(function($compile, $rootScope, $templateCache) { + $templateCache.put('thead.html', 'TD'); + expect(function() { + element = $compile('
')($rootScope); + }).not.toThrow(); + $rootScope.$digest(); + expect(nodeName_(element)).toMatch(/thead/i); + })); + it('should support templates with root tags', inject(function($compile, $rootScope, $templateCache) { $templateCache.put('tbody.html', 'TD'); expect(function() { @@ -1508,6 +1547,15 @@ describe('$compile', function() { $rootScope.$digest(); expect(nodeName_(element)).toMatch(/tbody/i); })); + + it('should support templates with root tags', inject(function($compile, $rootScope, $templateCache) { + $templateCache.put('tfoot.html', 'TD'); + expect(function() { + element = $compile('
')($rootScope); + }).not.toThrow(); + $rootScope.$digest(); + expect(nodeName_(element)).toMatch(/tfoot/i); + })); });