From d4c4a8943168eae9f7c70f25c42d7b5a6b5ccf8f Mon Sep 17 00:00:00 2001 From: Marc Laval Date: Thu, 28 Mar 2019 12:30:08 +0100 Subject: [PATCH] fix(ivy): host attributes and @COmponentChild should be supported on the same component (#29565) PR Close #29565 --- packages/core/src/render3/component.ts | 12 ++++++------ .../core/test/acceptance/integration_spec.ts | 17 ++++++++++++++++- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/packages/core/src/render3/component.ts b/packages/core/src/render3/component.ts index 16aa53f2a8..691d2d38a8 100644 --- a/packages/core/src/render3/component.ts +++ b/packages/core/src/render3/component.ts @@ -203,6 +203,12 @@ export function createRootComponent( hostFeatures && hostFeatures.forEach((feature) => feature(component, componentDef)); + // We want to generate an empty QueryList for root content queries for backwards + // compatibility with ViewEngine. + if (componentDef.contentQueries) { + componentDef.contentQueries(RenderFlags.Create, component, rootView.length - 1); + } + const rootTNode = getPreviousOrParentTNode(); if (tView.firstTemplatePass && componentDef.hostBindings) { const expando = tView.expandoInstructions !; @@ -217,12 +223,6 @@ export function createRootComponent( renderInitialStyles(native, rootTNode.stylingTemplate, componentView[RENDERER]); } - // We want to generate an empty QueryList for root content queries for backwards - // compatibility with ViewEngine. - if (componentDef.contentQueries) { - componentDef.contentQueries(RenderFlags.Create, component, rootView.length - 1); - } - return component; } diff --git a/packages/core/test/acceptance/integration_spec.ts b/packages/core/test/acceptance/integration_spec.ts index 7612e8b22e..041b7d6f63 100644 --- a/packages/core/test/acceptance/integration_spec.ts +++ b/packages/core/test/acceptance/integration_spec.ts @@ -5,7 +5,7 @@ * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ -import {Component, Directive, HostBinding, HostListener, Input, QueryList, ViewChildren} from '@angular/core'; +import {Component, ContentChild, Directive, HostBinding, HostListener, Input, QueryList, TemplateRef, ViewChildren} from '@angular/core'; import {TestBed} from '@angular/core/testing'; import {By} from '@angular/platform-browser'; import {expect} from '@angular/platform-browser/testing/src/matchers'; @@ -102,4 +102,19 @@ describe('acceptance integration tests', () => { fixture.detectChanges(); }).not.toThrow(); }); + + it('should support host attribute and @ContentChild on the same component', () => { + @Component( + {selector: 'test-component', template: `foo`, host: {'[attr.aria-disabled]': 'true'}}) + class TestComponent { + @ContentChild(TemplateRef) tpl !: TemplateRef; + } + + TestBed.configureTestingModule({declarations: [TestComponent]}); + const fixture = TestBed.createComponent(TestComponent); + fixture.detectChanges(); + + expect(fixture.componentInstance.tpl).not.toBeNull(); + expect(fixture.debugElement.nativeElement.getAttribute('aria-disabled')).toBe('true'); + }); });