如何在Angular中的CSS中添加其他样式属性? [英] How can I add additional style properties in CSS in Angular?

查看:733
本文介绍了如何在Angular中的CSS中添加其他样式属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应该设置文本元素字体大小的属性。到目前为止我试过这个:

I have a property which should set the font size of a text element. I've tried this so far:

<textarea 
  placeholder="Enter your TAX ID" 
  id="tax" 
  [(ngModel)]="tax_out" 
  [(ngModel)]="tax_in" 
  style="width: 100%; height: 100%; position: relative; bottom: 0px; fontsize: {{fontsize}}">
</textarea>

很遗憾没有成功。

我得到了这在logcat中:

I get this in logcat:


警告:清理不安全的样式值宽度:100%;高度:100%;
位置:相对; bottom:0px; fontsize :(参见
http://g.co/ng/security #xss )。

[WARN] TypeError:无法设置[object Object]的属性样式,其中
只有一个getter

"[WARN] TypeError: Cannot set property style of [object Object] which has only a getter"

ERROR,来源:ng:///AppModule/ModalContentPage.ngfactory.js(154)

"ERROR", source: ng:///AppModule/ModalContentPage.ngfactory.js (154)

ERROR CONTEXT,来源:ng:///AppModule/ModalContentPage.ngfactory.js(154)

"ERROR CONTEXT", source: ng:///AppModule/ModalContentPage.ngfactory.js (154)


推荐答案

如果它只是一种风格,你可以使用属性绑定

If it's just a single style, you can use property binding for this:

<textarea [style.font-size.px]="fontsize" ... style="width: 100%; height: 100%; position: relative; bottom: 0px;"></textarea>

请看一下 ngStyle docs 如果您需要动态设置多个样式,请获取更多信息:

Please take a look at the ngStyle docs for more info if you need to set more than one style dynamically:

<some-element [ngStyle]="{'font-style': styleExp}">...</some-element>    
<some-element [ngStyle]="{'max-width.px': widthExp}">...</some-element>    
<some-element [ngStyle]="objExp">...</some-element>

这篇关于如何在Angular中的CSS中添加其他样式属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆