【发布时间】:2021-01-10 23:50:36
【问题描述】:
我有一个采用 ng 样式的元素,但是当样式对象更改时,样式并不总是按预期应用。我专门指的是下面的 css animation,但我已经看到 background 的类似行为。
<div [ngStyle]="_innerStyle">
export class WidgetContainerComponent implements OnInit {
_innerStyle?: {
[klass: string]: any;
} | null;
...
}
例如_innerStyle是
animation: "flash"
animation-duration: "1s"
animation-iteration-count: "infinite"
background-color: "#ffffff"
box-shadow: "0px 2px 1px -1px rgba(0,0,0,.2), 0px 1px 1px 0px rgba(0,0,0,.14), 0px 1px 3px 0px rgba(0,0,0,.12)"
color: "#199719"
DOM 中的结果:
animation: 1s ease 0s infinite normal none running flash;
和变化
animation: "rubberBand"
animation-duration: "1s"
animation-iteration-count: "infinite"
background-color: "#b53b3b"
box-shadow: "0px 2px 1px -1px rgba(0,0,0,.2), 0px 1px 1px 0px rgba(0,0,0,.14), 0px 1px 3px 0px rgba(0,0,0,.12)"
color: "#199719"
DOM 中的结果:
0s ease 0s infinite normal none running flash
为什么animation-duration 突然被设置为0s?我正在打印 JSON 对象,它没有 0s 它有 1s。
更奇怪的是,如果 animation-duration 是不同的值,它们会在更改时正确应用?!例如:1s 到 2s 而不是 1s 到 1s
我希望 dom 样式能够准确地反映样式对象。难道我做错了什么?!有没有办法调试 ngStyles 的行为?
【问题讨论】: