fix(compiler): assume queries with no matches as static (#15429)
This has the side effect of allowing `@Input` and `@ContentChild` on the same property if the query is static (see the bug description for details). Fixes #15417
This commit is contained in:

committed by
Victor Berchet

parent
92084f2b6a
commit
c8ab5cb0c5
@ -6,7 +6,7 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {ANALYZE_FOR_ENTRY_COMPONENTS, Component, Directive, InjectionToken, Injector, Input, Pipe, PipeTransform, Provider, QueryList, Renderer2, SimpleChanges, TemplateRef, ViewChildren, ViewContainerRef} from '@angular/core';
|
||||
import {ANALYZE_FOR_ENTRY_COMPONENTS, Component, ContentChild, Directive, InjectionToken, Injector, Input, Pipe, PipeTransform, Provider, QueryList, Renderer2, SimpleChanges, TemplateRef, ViewChildren, ViewContainerRef} from '@angular/core';
|
||||
import {TestBed, fakeAsync, tick} from '@angular/core/testing';
|
||||
import {By} from '@angular/platform-browser';
|
||||
import {expect} from '@angular/platform-browser/testing/src/matchers';
|
||||
@ -336,6 +336,35 @@ function declareTests({useJit}: {useJit: boolean}) {
|
||||
expect(fixture.debugElement.childNodes.length).toBe(2);
|
||||
});
|
||||
});
|
||||
|
||||
it('should support @ContentChild and @Input on the same property for static queries', () => {
|
||||
@Directive({selector: 'test'})
|
||||
class Test {
|
||||
@Input() @ContentChild(TemplateRef) tpl: TemplateRef<any>;
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'my-app',
|
||||
template: `
|
||||
<test></test><br>
|
||||
<test><ng-template>Custom as a child</ng-template></test><br>
|
||||
<ng-template #custom>Custom as a binding</ng-template>
|
||||
<test [tpl]="custom"></test><br>
|
||||
`
|
||||
})
|
||||
class App {
|
||||
}
|
||||
|
||||
const fixture =
|
||||
TestBed.configureTestingModule({declarations: [App, Test]}).createComponent(App);
|
||||
fixture.detectChanges();
|
||||
|
||||
const testDirs =
|
||||
fixture.debugElement.queryAll(By.directive(Test)).map(el => el.injector.get(Test));
|
||||
expect(testDirs[0].tpl).toBeUndefined();
|
||||
expect(testDirs[1].tpl).toBeDefined();
|
||||
expect(testDirs[2].tpl).toBeDefined();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user