您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

Angular5给组件本身的标签添加样式class的方法

2024/3/19 21:39:20发布15次查看
本篇文章主要介绍了angular 5 给组件本身的标签添加样式class的方法,现在分享给大家,也给大家做个参考。
在angular 5给组件本身的标签添加样式有两种方法:
方式一:使用@component的host属性
@component({ selector : 'mycomponent', host : { '[style.color]' : "'red'", '[style.background-color]' : 'backgroundcolor' } }) class mycomponent { backgroundcolor: string; constructor() { this.backgroundcolor = 'blue'; } }
在host配置里添加属性,等同于标签上绑定属性的用法一样。
设置style:
'[style.color]': "'red'":注意red值双引号里还有一个单引号。
'[style.background-color]':'backgroundcolor':这里是引用了组件里的变量backgroudcolor。
这种方式的好处是可以在样式上使用组件的变量。
设置class:
@component({ selector : 'mycomponent', host : { '[class.myclass]' : 'showmyclass' } }) class mycomponent { showmyclass = false; constructor() { } togglemyclass() { this.showmyclass = !this.showmyclass; } }
方式二:在样式里使用:host选择器
@component({ selector : 'mycomponent', styles : [` :host { color: red; background-color: blue; } `] }) class mycomponent {}
上面是我整理给大家的,希望今后会对大家有帮助。
相关文章:
ajax上传实现根据服务器端返回数据进行js处理的方法
双层ajax嵌套(可多层)用法实例
ajax实现弹出式无刷新城市选择功能代码
以上就是angular5给组件本身的标签添加样式class的方法的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product