Skip to content

Commit d4c4a89

Browse files
marclavaljasonaden
authored andcommitted
fix(ivy): host attributes and @COmponentChild should be supported on the same component (angular#29565)
PR Close angular#29565
1 parent 12c9bd2 commit d4c4a89

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

packages/core/src/render3/component.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,12 @@ export function createRootComponent<T>(
203203

204204
hostFeatures && hostFeatures.forEach((feature) => feature(component, componentDef));
205205

206+
// We want to generate an empty QueryList for root content queries for backwards
207+
// compatibility with ViewEngine.
208+
if (componentDef.contentQueries) {
209+
componentDef.contentQueries(RenderFlags.Create, component, rootView.length - 1);
210+
}
211+
206212
const rootTNode = getPreviousOrParentTNode();
207213
if (tView.firstTemplatePass && componentDef.hostBindings) {
208214
const expando = tView.expandoInstructions !;
@@ -217,12 +223,6 @@ export function createRootComponent<T>(
217223
renderInitialStyles(native, rootTNode.stylingTemplate, componentView[RENDERER]);
218224
}
219225

220-
// We want to generate an empty QueryList for root content queries for backwards
221-
// compatibility with ViewEngine.
222-
if (componentDef.contentQueries) {
223-
componentDef.contentQueries(RenderFlags.Create, component, rootView.length - 1);
224-
}
225-
226226
return component;
227227
}
228228

packages/core/test/acceptance/integration_spec.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8-
import {Component, Directive, HostBinding, HostListener, Input, QueryList, ViewChildren} from '@angular/core';
8+
import {Component, ContentChild, Directive, HostBinding, HostListener, Input, QueryList, TemplateRef, ViewChildren} from '@angular/core';
99
import {TestBed} from '@angular/core/testing';
1010
import {By} from '@angular/platform-browser';
1111
import {expect} from '@angular/platform-browser/testing/src/matchers';
@@ -102,4 +102,19 @@ describe('acceptance integration tests', () => {
102102
fixture.detectChanges();
103103
}).not.toThrow();
104104
});
105+
106+
it('should support host attribute and @ContentChild on the same component', () => {
107+
@Component(
108+
{selector: 'test-component', template: `foo`, host: {'[attr.aria-disabled]': 'true'}})
109+
class TestComponent {
110+
@ContentChild(TemplateRef) tpl !: TemplateRef<any>;
111+
}
112+
113+
TestBed.configureTestingModule({declarations: [TestComponent]});
114+
const fixture = TestBed.createComponent(TestComponent);
115+
fixture.detectChanges();
116+
117+
expect(fixture.componentInstance.tpl).not.toBeNull();
118+
expect(fixture.debugElement.nativeElement.getAttribute('aria-disabled')).toBe('true');
119+
});
105120
});

0 commit comments

Comments
 (0)