fix(core): apply host attributes to root elements (#12761)

Fixes #12744
This commit is contained in:
Tobias Bosch 2016-11-08 15:46:55 -08:00 committed by vikerman
parent a0e9fde653
commit ad3bf6c54f
2 changed files with 17 additions and 1 deletions

View File

@ -358,6 +358,9 @@ export function selectOrCreateRenderHostElement(
var hostElement: any;
if (isPresent(rootSelectorOrNode)) {
hostElement = renderer.selectRootElement(rootSelectorOrNode, debugInfo);
for (var i = 0; i < attrs.length; i += 2) {
renderer.setElementAttribute(hostElement, attrs.get(i), attrs.get(i + 1));
}
} else {
hostElement = createRenderElement(renderer, null, elementName, attrs, debugInfo);
}

View File

@ -830,7 +830,20 @@ function declareTests({useJit}: {useJit: boolean}) {
expect(listener.eventTypes).toEqual([]);
});
it('should support updating host element via hostAttributes', () => {
it('should support updating host element via hostAttributes on root elements', () => {
@Component({host: {'role': 'button'}, template: ''})
class ComponentUpdatingHostAttributes {
}
TestBed.configureTestingModule({declarations: [ComponentUpdatingHostAttributes]});
const fixture = TestBed.createComponent(ComponentUpdatingHostAttributes);
fixture.detectChanges();
expect(getDOM().getAttribute(fixture.debugElement.nativeElement, 'role')).toEqual('button');
});
it('should support updating host element via hostAttributes on host elements', () => {
TestBed.configureTestingModule({declarations: [MyComp, DirectiveUpdatingHostAttributes]});
const template = '<div update-host-attributes></div>';
TestBed.overrideComponent(MyComp, {set: {template}});