If you want to style host component. You can use ':host-context'.

// host

@Component({
selector: 'my-app',
template: `
<div class="styled-component">
<hostcontext-styling></hostcontext-styling>
</div>
`,
})

In the host component, we have 'styled-component' class, we want to apply some css to it from the child component:

import { Component } from '@angular/core';

@Component({
selector: 'hostcontext-styling',
template: `
<div>
I'm a div that wants to be styled
</div>
`,
styles: [
`
/* apply a border if any of our ancestors has .styled-component applied */
:host-context(.styled-component) {
border: 1px solid gray;
display:block;
}
`
]
})
export class HostContextStylingComponent {
}

Now if we want to style its child component, we can use '::ng-deep':

import { Component } from '@angular/core';

@Component({
selector: 'hostcontext-styling',
template: `
<div>
I'm a div that wants to be styled
</div>
<child-component></child-component>
`,
styles: [
`
/* apply a border if any of our ancestors has .styled-component applied */
:host-context(.styled-component) {
border: 1px solid gray;
display:block;
} :host ::ng-deep p {
background-color: yellow;
}
`
]
})
export class HostContextStylingComponent {
}

最新文章

  1. java高新技术-操作javaBean
  2. php memcache扩展 出现错误dyld: Symbol not found: _mmc_queue_free
  3. codeforces 689 E. Mike and Geometry Problem 组合数学 优先队列
  4. PHP换行符详解 PHP_EOL,&lt;br /&gt;
  5. Part 13 Cast and Convert functions in SQL Server
  6. 【转】Bash中的shopt选项
  7. MySQL【第一篇】安装
  8. openerp 报表字段 report_rml_content_data
  9. MQ日常维护操作手册
  10. 算法模板——KMP字符串匹配
  11. Win10隐藏硬盘分区
  12. ThinkPhp框架:分页查询和补充框架知识
  13. python基础知识巩固(os.walk)
  14. vsftpd详细配置
  15. python列表1
  16. 剑指offer——python【第56题】删除链表中的重复节点
  17. PostgreSQL 使用小点
  18. Ajax之跨域访问与JSONP
  19. django2.0 官方中文文档地址
  20. webApi2 上传大文件代码

热门文章

  1. LeetCode 0、《两数相加》
  2. Ubuntu16.04+Gnome3 锁定屏幕快捷键无效解决办法
  3. 搭建专属于自己的Leanote云笔记本
  4. pip版本及升级 pip安装指定模板
  5. Android manifest文件中的标签详细介绍
  6. CCF模拟 无线网络
  7. 在XEN上启动guest时loopback设备不足
  8. HBase写入操作卡住长时间不返回的原因分析
  9. Python 面向对象 —— 多重继承
  10. mvc的个别对输入数据的验证