fix(ivy): unable to inherit view queries into component from directive (#29203)
Fixes components not being able to inherit their view queries from a directive. This PR resolves FW-1146. PR Close #29203
This commit is contained in:

committed by
Matias Niemelä

parent
a5a35ff54a
commit
0ffa2f2e73
@ -17,7 +17,8 @@ describe('query logic', () => {
|
||||
declarations: [
|
||||
AppComp, QueryComp, SimpleCompA, SimpleCompB, StaticViewQueryComp, TextDirective,
|
||||
SubclassStaticViewQueryComp, StaticContentQueryComp, SubclassStaticContentQueryComp,
|
||||
QueryCompWithChanges, StaticContentQueryDir
|
||||
QueryCompWithChanges, StaticContentQueryDir, SuperDirectiveQueryTarget, SuperDirective,
|
||||
SubComponent
|
||||
]
|
||||
});
|
||||
});
|
||||
@ -161,6 +162,17 @@ describe('query logic', () => {
|
||||
expect(secondComponent.setEvents).toEqual(['textDir set', 'foo set']);
|
||||
});
|
||||
|
||||
it('should allow for view queries to be inherited from a directive', () => {
|
||||
const fixture = TestBed.createComponent(SubComponent);
|
||||
const comp = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(comp.headers).toBeTruthy();
|
||||
expect(comp.headers.length).toBe(2);
|
||||
expect(comp.headers.toArray().every(result => result instanceof SuperDirectiveQueryTarget))
|
||||
.toBe(true);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('content queries', () => {
|
||||
@ -484,7 +496,7 @@ class StaticViewQueryComp {
|
||||
template: `
|
||||
<div [text]="text"></div>
|
||||
<span #foo></span>
|
||||
|
||||
|
||||
<div #bar></div>
|
||||
<span #baz></span>
|
||||
`
|
||||
@ -564,3 +576,21 @@ export class QueryCompWithChanges {
|
||||
|
||||
showing = false;
|
||||
}
|
||||
|
||||
@Component({selector: 'query-target', template: '<ng-content></ng-content>'})
|
||||
class SuperDirectiveQueryTarget {
|
||||
}
|
||||
|
||||
@Directive({selector: '[super-directive]'})
|
||||
class SuperDirective {
|
||||
@ViewChildren(SuperDirectiveQueryTarget) headers !: QueryList<SuperDirectiveQueryTarget>;
|
||||
}
|
||||
|
||||
@Component({
|
||||
template: `
|
||||
<query-target>One</query-target>
|
||||
<query-target>Two</query-target>
|
||||
`
|
||||
})
|
||||
class SubComponent extends SuperDirective {
|
||||
}
|
||||
|
Reference in New Issue
Block a user