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.

Possibility to add class="" using <ng-content>

See original GitHub issue

Feature Request

Description

Currently the ng-content tag is just a placeholder that will be replaced. When creating eg. a component library we might get code that is encapsulated and not easily styled by the library consumers.

eg.

<ng-content select="header"></ng-content>
<div class="content">
  <div class="body">
    <ng-content></ng-content>
  </div>
</div>

in this case the body class has a padding and to be able to change that padding library consumer need to use something like ::ng-deep.

Describe the solution you’d like

Something like this perhaps?

<ng-content select="header"></ng-content>
<ng-content class="content"  select="content">
  <ng-content class="body"  select="body">
  </ng-content>
</ng-content>

and the classes would be merged… This would allow ui component creator to have default styling and also make it easier to the consumers of the component to add styling 😃

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
vugar005commented, May 31, 2021

Hi @indraraj26 , Thanks for example. The problem in example is you are using

.child-body :host-context(.body) {
  color: red;
}

But element with body class is not parent of .child-content, it is sibling. I changed it to

.child-body :host-context(.outer-box) {
  color: red;
}

and it worked.

0reactions
angular-automatic-lock-bot[bot]commented, Jul 2, 2021

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Custom Styling on <ng-content> in angular2 not working
According to the web components spec ::content should be enough and >>> should not be required but the styles were not applied without...
Read more >
Angular ng-content and Content Projection: A Complete Guide ...
So let's implement a small component without using content ... the input is simulated by adding a focus css class to the host...
Read more >
Components-constructors: the power of ng-content in Angular
We can have several ng-content s in one template and choose between them with select attribute. It takes any CSS selector: element name,...
Read more >
ng-content in Angular - GeeksforGeeks
The ng-content is used when we want to insert the content dynamically inside the component that helps to increase component reusability. Using ......
Read more >
Using ng-content for Content Projection - DEV Community ‍ ‍
To solve this, ng-content has a property named select . If you specify select with a CSS matching selector, it will get only...
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