Skip to content

Styles not being applied to custom component selectors #5702

@LanceEa

Description

@LanceEa

I'm running into an issue with applying styles to custom elements. I'm not sure if it is a bug or my lack of understanding. I have a simple component called <my-cmp></my-cmp> which I want to apply styles to it as part of the component definition.

Here is an example of my components and what I'm trying to do.

import {Component, CORE_DIRECTIVES} from 'angular2/angular2'

@Component({
  selector: "my-cmp",
  template: `
    <ng-content></ng-content>
  `,
  styles: [`
    my-list {
      display: block;
      border: 1px solid black;
      min-height: 200px;
    }
  `]
})
export class MyCmp {}

@Component({
  selector: 'my-app',
  template: `
      <h2>Angular 2 Styles Issue?</h2>
      <my-cmp>
        <p>Why are style's not being applied to custom component selector "my-list"?</p>
      </my-cmp>
  `,
  directives: [CORE_DIRECTIVES, MyCmp]
})
export class App {}

I would expect the outputted html to look something like this with the styles applying directly to the my-cmp. MyComponent should have a border around it but nothing is applied to it.

<my-app>
  <my-cmp>
        <p>Why are style's not being applied to custom component selector "my-list"?</p>
  </my-list>
</my-cmp>

Here is a plunker demonstrating this example.
http://plnkr.co/edit/w6EYcxLDsLaXXjhdHDh0

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