fix(core): apply host attributes to root elements (#12761)
Fixes #12744
This commit is contained in:
parent
a0e9fde653
commit
ad3bf6c54f
|
@ -358,6 +358,9 @@ export function selectOrCreateRenderHostElement(
|
||||||
var hostElement: any;
|
var hostElement: any;
|
||||||
if (isPresent(rootSelectorOrNode)) {
|
if (isPresent(rootSelectorOrNode)) {
|
||||||
hostElement = renderer.selectRootElement(rootSelectorOrNode, debugInfo);
|
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 {
|
} else {
|
||||||
hostElement = createRenderElement(renderer, null, elementName, attrs, debugInfo);
|
hostElement = createRenderElement(renderer, null, elementName, attrs, debugInfo);
|
||||||
}
|
}
|
||||||
|
|
|
@ -830,7 +830,20 @@ function declareTests({useJit}: {useJit: boolean}) {
|
||||||
expect(listener.eventTypes).toEqual([]);
|
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]});
|
TestBed.configureTestingModule({declarations: [MyComp, DirectiveUpdatingHostAttributes]});
|
||||||
const template = '<div update-host-attributes></div>';
|
const template = '<div update-host-attributes></div>';
|
||||||
TestBed.overrideComponent(MyComp, {set: {template}});
|
TestBed.overrideComponent(MyComp, {set: {template}});
|
||||||
|
|
Loading…
Reference in New Issue