From ad3bf6c54fcb68279e905387b8f6fb0ff1f81dd6 Mon Sep 17 00:00:00 2001 From: Tobias Bosch Date: Tue, 8 Nov 2016 15:46:55 -0800 Subject: [PATCH] fix(core): apply host attributes to root elements (#12761) Fixes #12744 --- modules/@angular/core/src/linker/view_utils.ts | 3 +++ .../@angular/core/test/linker/integration_spec.ts | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/modules/@angular/core/src/linker/view_utils.ts b/modules/@angular/core/src/linker/view_utils.ts index da295153d0..a564e192f4 100644 --- a/modules/@angular/core/src/linker/view_utils.ts +++ b/modules/@angular/core/src/linker/view_utils.ts @@ -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); } diff --git a/modules/@angular/core/test/linker/integration_spec.ts b/modules/@angular/core/test/linker/integration_spec.ts index a247cbf15e..6d0e07fa5e 100644 --- a/modules/@angular/core/test/linker/integration_spec.ts +++ b/modules/@angular/core/test/linker/integration_spec.ts @@ -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 = '
'; TestBed.overrideComponent(MyComp, {set: {template}});