Skip to content

Can't style content added with ng-content directive #11841

Closed

Description

@chrisnicola

I'm submitting a ... (check one with "x")

[x] bug report => search github for a similar issue or PR before submitting

Current behavior

Currently it appears that content inside of a content block using <ng-content> does not work with Angular 2's component styling. It does not receive any of the component namespace attributes the rest of the component receives but any styling meant for that content is namespaced.

So for example this template

<div class="my-component">
  <ng-content></ng-content>
</div>

With this style:

.my-component > * { margin-top: 10px; }

Will not apply the style to any of the child elements loaded by <ng-content>

Expected behavior

I would expect these styles to be applied.

Reproduction of the problem
http://plnkr.co/edit/MsNXmn90arPXmY4x1mD0?p=preview

What is the motivation / use case for changing the behavior?
That the stylesheet does not apply styles to the injected content is unexpected and I suspect will be surprising to a large number of people. I also think it is a difficult limitation to cleanly work around.

  • Angular version: 2.0.0
  • Language: [TypeScript 2.0.2]

Activity

  1. vicb commented on Sep 22, 2016

    @vicb
    Contributor

    That the stylesheet does not apply styles to the injected content is unexpected

    That's how it is supposed to work, see the shadow dom spec.

    Having said that :slotted is not yet supported. A workaround for now is to use /deep/, see #11595

  2. chrisnicola commented on Sep 22, 2016

    @chrisnicola
    Author

    Ah thanks for the workaround.

  3. angular-automatic-lock-bot commented on Sep 9, 2019

    @angular-automatic-lock-bot

    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.

  4. locked and limited conversation to collaborators on Sep 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions