跳到正文
本页尚未翻译成中文,以下为英文原文。 查看英文版

Invalid style property binding value ​

Angular detected a value with an unsupported type in a style property binding. This can occur in an individual binding such as [style.width] or in a property of a [style] map.

Style property values accept strings, numbers, style SafeValue objects, null, and undefined. Other values, including SafeValue objects created for a non-style security context, produce this warning in development mode.

For example, the following binding passes a boolean instead of a CSS value:

html
<div [style.display]="isVisible"></div>

Debugging the error ​

Use the property name and value in the error message to locate the binding. Convert the value to a valid CSS string or number, or use null or undefined to remove the style.

When using a unit suffix such as [style.width.px], bind the numeric portion of the value:

html
<div [style.width.px]="width"></div>

Do not pass a SafeValue created for another security context, such as trusted HTML, to a style property binding.

基于 MIT 许可证发布。