question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Make content projection selectors more lenient

See original GitHub issue

For 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:closed
  • Created 4 years ago
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
SvenBudakcommented, May 24, 2019

But why not simply add in material elements a selector for class variant? this is much more easy for usage…

1reaction
ViktorSlavovcommented, May 20, 2019

@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 all select="[mat-card-avatar]"), so it can fulfill ng-content’s [select] requirements.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found