mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-04-29 05:15:38 +08:00
fix($compile): remove comment nodes from templates before asserting single root node
The compiler will no longer throw if a directive template contains comment nodes in addition to a single root node. If a template contains less than 2 nodes, the nodes are unaltered. BREAKING CHANGE: If a template contains directives within comment nodes, and there is more than a single node in the template, those comment nodes are removed. The impact of this breaking change is expected to be quite low. Closes #9212 Closes #9215
This commit is contained in:
@@ -1078,6 +1078,22 @@ describe('$compile', function() {
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
it('should ignore comment nodes when replacing with a template', function() {
|
||||
module(function() {
|
||||
directive('replaceWithComments', valueFn({
|
||||
replace: true,
|
||||
template: '<!-- ignored comment --><p>Hello, world!</p><!-- ignored comment-->'
|
||||
}));
|
||||
});
|
||||
inject(function($compile, $rootScope) {
|
||||
expect(function() {
|
||||
element = $compile('<div><div replace-with-comments></div></div>')($rootScope);
|
||||
}).not.toThrow();
|
||||
expect(element.find('p').length).toBe(1);
|
||||
expect(element.find('p').text()).toBe('Hello, world!');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -1977,6 +1993,26 @@ describe('$compile', function() {
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
it('should ignore comment nodes when replacing with a templateUrl', function() {
|
||||
module(function() {
|
||||
directive('replaceWithComments', valueFn({
|
||||
replace: true,
|
||||
templateUrl: 'templateWithComments.html'
|
||||
}));
|
||||
});
|
||||
inject(function($compile, $rootScope, $httpBackend) {
|
||||
$httpBackend.whenGET('templateWithComments.html').
|
||||
respond('<!-- ignored comment --><p>Hello, world!</p><!-- ignored comment-->');
|
||||
expect(function() {
|
||||
element = $compile('<div><div replace-with-comments></div></div>')($rootScope);
|
||||
}).not.toThrow();
|
||||
$httpBackend.flush();
|
||||
expect(element.find('p').length).toBe(1);
|
||||
expect(element.find('p').text()).toBe('Hello, world!');
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user