feat(compiler): Add ngProjectAs to Directive and Component metadata
See original GitHub issueWhich @angular/* package(s) are relevant/releated to the feature request?
compiler
Description
Presently we can specify ngProjectAs on an element to trick ViewChild and <ng-container> into picking it up.
Example:
<mat-form-field> <my-bundle-o-errors ngProjectAs="mat-error"> </my-bundle-o-errors> </mat-form-field>However, this requires correctly repeating ngProjectAs=“mat-error” on every invocation of that component.
Proposed solution
By adding ngProjectAs to Directive, we can allow the renamed projection to work for every instance of a component or directive.
The behavior would be the same as when it appears on an element (effectively setting ngProjectAs on the host element at compile time).
Alternatives considered
If desired, this could be limited to Component rather than Directive metadata.
The code snipped above can be augmented with runtime assertions that ensure ngProjectAs is present:
@Input() ngProjectAs?: string;
ngOnInit() {
if (this.ngProjectAs !== 'mat-error') throw new Error('ngProjectAs="mat-error" is required');
}
Still not as nice as being able to include it in the component’s own definition.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:7 (6 by maintainers)
Top Results From Across the Web
Directive - Angular
When present, this directive/component is ignored by the AOT compiler. ... The options provide configuration metadata that determines how the directive ...
Read more >Need ability to add directives to host elements in component ...
I've been digging into Angular 2 and have run into a potential road block for extending certain kinds of components. In the the...
Read more >angular - When is a directive required in component metadata ...
A component needs to define in its directives the Components/Directive which are referenced within its template via their selectors.
Read more >Angular Directive Tutorial With Example | Custom Directives
This blog will introduce you to Angular Directive with sample codes for better understanding. You will also learn about Custom Directives in ...
Read more >Difference between Angular directives vs components - eduCBA
To make the newly created Angular Component a member of NgModule, we should be adding this component name in the declarations field of...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The behavior could be additive - projection could match both the actual as well as the “projected as” signature.
Often times, the projecting component is not owned by the same entity as the new directive/component being implemented. In my case, the motive for this is being able to use the mat-error slot in mat-form-field.
This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.