如何在 Angular 的 CSS 中添加其他样式属性? [英] How can I add additional style properties in CSS in Angular?
问题描述
我有一个属性可以设置文本元素的字体大小.到目前为止我已经尝试过了:
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%;位置:相对;底部:0px;字体大小:(见http://g.co/ng/security#xss)."
"WARNING: sanitizing unsafe style value width: 100%; height: 100%; position: relative; bottom: 0px; fontsize: (see http://g.co/ng/security#xss)."
"[WARN] TypeError: Cannot set property style of [object Object] which只有一个吸气剂"
"[WARN] TypeError: Cannot set property style of [object Object] which has only a getter"
错误",来源:ng:///AppModule/ModalContentPage.ngfactory.js (154)
"ERROR", source: ng:///AppModule/ModalContentPage.ngfactory.js (154)
错误上下文",来源: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 文档了解更多信息动态不止一种样式:
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屋!