Make content projection selectors more lenient
See original GitHub issueFor example i tryed to pass a own component as mat-card-avatar
into the <mat-card-header>
:
<mat-card-header>
<app-image class="mat-card-avatar"></app-image>
<mat-card-title>Name</mat-card-title>
<mat-card-subtitle>Subtitle</mat-card-subtitle>
</mat-card-header>
But this dont work, because <mat-card-header>
allow only his own sub components on correct place: https://github.com/angular/components/blob/master/src/material/card/card-header.html
<ng-content select="[mat-card-avatar], [matCardAvatar]"></ng-content>
<div class="mat-card-header-text">
<ng-content
select="mat-card-title, mat-card-subtitle,
[mat-card-title], [mat-card-subtitle],
[matCardTitle], [matCardSubtitle]"></ng-content>
</div>
<ng-content></ng-content>
Please add [.mat-card-avatar]
as class to line 1.
Would be good if this is possible in every material component.
The current solution looks like:
<mat-card-header>
<div mat-card-avatar>
<app-image class="mat-card-avatar"></app-image>
</div>
<mat-card-title>Name</mat-card-title>
<mat-card-subtitle>Subtitle</mat-card-subtitle>
</mat-card-header>
Issue Analytics
- State:
- Created 4 years ago
- Comments:11 (5 by maintainers)
Top Results From Across the Web
Content projection - Angular
Each slot can specify a CSS selector that determines which content goes into that slot. This pattern is referred to as multi-slot content...
Read more >How to style ng-content - Stack Overflow
2. Use the :host /deep/ selector. If you want to use the shadow DOM polyfill and style your components using the style or...
Read more >Angular ng-content and Content Projection: A Complete Guide ...
In this post, we are going to learn how to use this feature to design components that have a very simple but still...
Read more >Transclusion in Angular 2 with ng-content - Ultimate Courses
This is now done in Angular through modern web APIs such as Shadow DOM and known as “Content Projection”. Let's explore! Table of...
Read more >5. Working with the Shadow DOM - Modern JavaScript [Book]
One of the aspects of the DOM that makes development of ... The shadow DOM takes this principle one step further. ... Projection...
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
But why not simply add in material elements a selector for class variant? this is much more easy for usage…
@SvenBudak You can refer to the following StackBlitz example to see how you can use
ngProjectAs
for your case. The feature is not really well documented on the Angular wiki, but it basically allows a part of your template (i.e.app-image
) to project itself as whatever you specify (i.e.ngProjectAs="[mat-card-avatar]"
, meaning it will get caught by allselect="[mat-card-avatar]"
), so it can fulfillng-content
’s[select]
requirements.