css - Angular 2: How to style host element of the component? -


i have component in angular 2 called my-comp:

<my-comp></my-comp> 

how 1 style host element of component in angular 2?

in polymer, use ":host" selector. tried in angular 2. doesn't work.

:host {   display: block;   width: 100%;   height: 100%; } 

i tried using component selector:

my-comp {   display: block;   width: 100%;   height: 100%; } 

both approaches don't seem work.

thanks.

there bug, fixed in meantime. :host { } works fine now.

also supported are

  • :host(selector) { ... } selector match attributes, classes, ... on host element
  • :host-context(selector) { ... } selector match elements, classes, ...on parent components

  • selector /deep/ selector (alias selector >>> selector doesn't work sass) styles match across element boundaries

    • update: sass deprecating /deep/.
      angular (ts , dart) added ::ng-deep replacement that's compatible sass.

see load external css style angular 2 component

/deep/ , >>> not affected same selector combinators in chrome deprecated.
angular emulates (rewrites) them, , therefore doesn't depend on browsers supporting them.

this why /deep/ , >>> don't work viewencapsulation.native enables native shadow dom , depends on browser support.


Comments

Popular posts from this blog

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

android - How to create dynamically Fragment pager adapter -

1111. appearing after print sequence - php -